Beispiel #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);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Editing workbookPr element
        /// </summary>
        /// <param name="filePath">Target Excel file path</param>
        /// <param name="log">Logger</param>
        public void EditElements(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.ChartTrackingReferenceBase.Value = false;

                    log.Pass("Edited ChartTrackingReferenceBase value.");

                    X15ac.AbsolutePath absolutePath = package.WorkbookPart.Workbook.AbsolutePath;
                    log.Verify(absolutePath != null, "Unable to obtain the X15ac.AbsolutePath.");
                    absolutePath.Url = "";
                }
                catch (Exception e)
                {
                    log.Fail(e.Message);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Verifying the workbookPr element the appending
        /// </summary>
        /// <param name="stream">Target Excel stream</param>
        /// <param name="log">Logger</param>
        public void VerifyAddElements(Stream stream, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(stream, false, new OpenSettings()
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013)
            }))
            {
                WorkbookExtensionList workbookExtensionList = package.WorkbookPart.Workbook.Descendants <WorkbookExtensionList>().Single();
                int workbookPrNum = workbookExtensionList.Descendants <X15.WorkbookProperties>().Count();
                log.Verify(workbookPrNum == 1, "Missing workbookPr element.");

                X15ac.AbsolutePath absolutePath = package.WorkbookPart.Workbook.AbsolutePath;
                log.Verify(absolutePath != null, "Missing X15ac.AbsolutePath element.");
            }
        }
Beispiel #4
0
        /// <summary>
        /// Verifying the workbookPr element the existence
        /// </summary>
        /// <param name="stream">Target Excel stream</param>
        /// <param name="log">Logger</param>
        public void VerifyElements(Stream stream, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(stream, false, new OpenSettings()
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013)
            }))
            {
                WorkbookExtensionList  workbookExtensionList = package.WorkbookPart.Workbook.Descendants <WorkbookExtensionList>().Single();
                X15.WorkbookProperties workbookProperties    = workbookExtensionList.Descendants <X15.WorkbookProperties>().Single();

                log.Verify(workbookProperties.ChartTrackingReferenceBase.Value == false, "UnChanged in the ChartTrackingReferenceBase attribute value on workbookPr element.");

                X15ac.AbsolutePath absolutePath = package.WorkbookPart.Workbook.AbsolutePath;
                Assert.NotNull(absolutePath);
                Assert.Equal(string.Empty, absolutePath.Url);
            }
        }
        /// <summary>
        /// Verifying the workbookPr element the existence
        /// </summary>
        /// <param name="filePath">Target Excel faile path</param>
        /// <param name="log">Logger</param>
        public void VerifyElements(string filePath, VerifiableLog log)
        {
            using (SpreadsheetDocument package = SpreadsheetDocument.Open(filePath, false, new OpenSettings()
            {
                MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode.ProcessAllParts, FileFormatVersions.Office2013)
            }))
            {
                WorkbookExtensionList  workbookExtensionList = package.WorkbookPart.Workbook.Descendants <WorkbookExtensionList>().Single();
                X15.WorkbookProperties workbookProperties    = workbookExtensionList.Descendants <X15.WorkbookProperties>().Single();

                log.Verify(workbookProperties.ChartTrackingReferenceBase.Value == false, "UnChanged in the ChartTrackingReferenceBase attribute value on workbookPr element.");

                X15ac.AbsolutePath absolutePath = package.WorkbookPart.Workbook.AbsolutePath;
                log.Verify(absolutePath != null, "Unable to obtain the X15ac.AbsolutePath.");
                log.Verify(absolutePath.Url == "", "X15ac.AbsolutePath uri value is not change.");
            }
        }