Exemplo n.º 1
0
        /// <summary>
        /// Deleting workbookPr element
        /// </summary>
        /// <param name="filePath">Target Excel faile path</param>
        /// <param name="log">Logger</param>
        public void DeleteElements(string filePath, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, true, new OpenSettings()
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013)
            }))
            {
                try
                {
                    WorkbookExtensionList  workbookExtensionList = package.WorkbookPart.Workbook.Descendants <WorkbookExtensionList>().Single();
                    X15.WorkbookProperties workbookProperties    = workbookExtensionList.Descendants <X15.WorkbookProperties>().Single();
                    workbookProperties.Remove();

                    WorkbookExtension workbookExtension = workbookExtensionList.Descendants <WorkbookExtension>().Where(e => e.Uri == this.workbookPrExtUri).Single();
                    workbookExtension.Remove();

                    log.Pass("Deleted workbookPr element.");

                    X15ac.AbsolutePath absolutePath = package.WorkbookPart.Workbook.AbsolutePath;
                    absolutePath.Remove();
                    log.Pass("Deleted AbsolutePath element.");
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }