Exemplo n.º 1
0
        /// <summary>
        /// Append the workbookpr element
        /// </summary>
        /// <param name="filePath">Target excel faile path</param>
        /// <param name="log">Logger</param>
        public void AddElement(string filePath, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, true, new OpenSettings()
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013)
            }))
            {
                try
                {
                    package.WorkbookPart.Workbook.AbsolutePath = null;
                    X15ac.AbsolutePath absolutePath = new X15ac.AbsolutePath()
                    {
                        Url = this.AbsolutePathUri
                    };
                    absolutePath.AddNamespaceDeclaration("x15ac", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac");

                    AlternateContentChoice alternateContentChoice = new AlternateContentChoice()
                    {
                        Requires = "x15"
                    };
                    alternateContentChoice.Append(absolutePath);
                    log.Pass("Added AbsolutePath element.");

                    AlternateContent alternateContent = new AlternateContent();
                    alternateContent.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
                    alternateContent.Append(alternateContentChoice);

                    package.WorkbookPart.Workbook.InsertAfter(alternateContent, package.WorkbookPart.Workbook.Descendants <WorkbookProperties>().First());
                    //package.WorkbookPart.Workbook.Append(alternateContent);
                    log.Pass("Added AlternateContentChoice element.");

                    WorkbookExtensionList workbookExtensionList = package.WorkbookPart.Workbook.Descendants <WorkbookExtensionList>().Single();
                    WorkbookExtension     workbookExtension     = new WorkbookExtension()
                    {
                        Uri = this.workbookPrExtUri
                    };
                    workbookExtension.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");

                    X15.WorkbookProperties workbookProperties = new X15.WorkbookProperties();
                    workbookProperties.ChartTrackingReferenceBase = false;

                    workbookExtension.AppendChild <X15.WorkbookProperties>(workbookProperties);
                    workbookExtensionList.AppendChild <WorkbookExtension>(workbookExtension);

                    log.Pass("Added workbookPr element.");
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Append the workbookpr element
        /// </summary>
        /// <param name="filePath">Target excel faile path</param>
        /// <param name="log">Logger</param>
        public void AddElement(string filePath, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, true, new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013) }))
            {
                try
                {
                    package.WorkbookPart.Workbook.AbsolutePath = null;
                    X15ac.AbsolutePath absolutePath = new X15ac.AbsolutePath() { Url = this.AbsolutePathUri };
                    absolutePath.AddNamespaceDeclaration("x15ac", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/ac");

                    AlternateContentChoice alternateContentChoice = new AlternateContentChoice() { Requires = "x15" };
                    alternateContentChoice.Append(absolutePath);
                    log.Pass("Added AbsolutePath element.");

                    AlternateContent alternateContent = new AlternateContent();
                    alternateContent.AddNamespaceDeclaration("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
                    alternateContent.Append(alternateContentChoice);

                    package.WorkbookPart.Workbook.InsertAfter(alternateContent, package.WorkbookPart.Workbook.Descendants<WorkbookProperties>().First());
                    //package.WorkbookPart.Workbook.Append(alternateContent);
                    log.Pass("Added AlternateContentChoice element.");

                    WorkbookExtensionList workbookExtensionList = package.WorkbookPart.Workbook.Descendants<WorkbookExtensionList>().Single();
                    WorkbookExtension workbookExtension = new WorkbookExtension() { Uri = this.workbookPrExtUri };
                    workbookExtension.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");

                    X15.WorkbookProperties workbookProperties = new X15.WorkbookProperties();
                    workbookProperties.ChartTrackingReferenceBase = false;

                    workbookExtension.AppendChild<X15.WorkbookProperties>(workbookProperties);
                    workbookExtensionList.AppendChild<WorkbookExtension>(workbookExtension);

                    log.Pass("Added workbookPr element.");
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }