예제 #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());
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Sets the extended document properties
 /// </summary>
 /// <param name="document">SpreadSheetDocument reference</param>
 /// <param name="company">Company</param>
 /// <param name="application">Application</param>
 public static void SetExtendedProperties(this SpreadsheetDocument document, Company company, Application application)
 {
     //Add extended Document properties
     if (document.ExtendedFilePropertiesPart == null)
     {
         document.AddExtendedFilePropertiesPart();
     }
     document.ExtendedFilePropertiesPart.Properties = new Properties
     {
         Company     = company ?? new Company(@"izrra.ch"),
         Application = application ?? new Application("Combine.Sdk.Excel")
     };
     //Save all changes
     document.Save();
 }
예제 #3
0
        /// <summary>
        /// Создает заготовку для документа Excel
        /// </summary>
        /// <param name="fileName">Полный путь к файлу</param>
        private void CreateSpreadSheetWorkBook(string fileName)
        {
            _document = SpreadsheetDocument.Create(fileName, SpreadsheetDocumentType.Workbook);
            SetPackageProperties();

            ExtendedFilePropertiesPart extendedPropertiesPart = _document.AddExtendedFilePropertiesPart();

            GenerateExtendedProperties(extendedPropertiesPart);

            _workbookPart = _document.AddWorkbookPart();

            WorkbookStylesPart workbookStyles = _workbookPart.AddNewPart <WorkbookStylesPart>("rId3");

            GenerateStyles(workbookStyles);

            _workbookPart.Workbook = new Workbook();
            _workbookPart.Workbook.AppendChild(new Sheets());
        }