Пример #1
0
        public void X006_Xlsx_DeleteAdd_CoreExtendedProperties()
        {
            var docName = "Spreadsheet.xlsx";
            var ba      = File.ReadAllBytes(s_TestFileLocation + docName);

            using (MemoryStream ms = new MemoryStream())
            {
                ms.Write(ba, 0, ba.Length);
                using (SpreadsheetDocument doc = SpreadsheetDocument.Open(ms, true))
                {
                    var corePart = doc.CoreFilePropertiesPart;
                    var appPart  = doc.ExtendedFilePropertiesPart;
                    doc.DeletePart(corePart);
                    doc.DeletePart(appPart);
                    doc.AddCoreFilePropertiesPart();
                    doc.AddExtendedFilePropertiesPart();
                    doc.AddCustomFilePropertiesPart();
                    doc.AddDigitalSignatureOriginPart();
                    doc.AddExtendedPart("relType", "contentType/xml", ".xml");
                    var tnPart = doc.AddThumbnailPart(ThumbnailPartType.Jpeg);
                    doc.DeletePart(tnPart);
                    tnPart = doc.AddThumbnailPart("image/jpg");
                    OpenXmlValidator v = new OpenXmlValidator(FileFormatVersions.Office2013);
                    var errs           = v.Validate(doc);
                    Assert.Equal(1, errs.Count());
                }
            }
        }