diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index 3d839de..1544814 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -334,14 +334,19 @@ GenerateThemePartContent(themePart); } + // Custom properties if (CustomProperties.Any()) { - document.GetPartsOfType().ToList().ForEach(p => document.DeletePart(p)); var customFilePropertiesPart = - document.AddNewPart(context.RelIdGenerator.GetNext(RelType.Workbook)); + document.CustomFilePropertiesPart ?? document.AddNewPart(context.RelIdGenerator.GetNext(RelType.Workbook)); GenerateCustomFilePropertiesPartContent(customFilePropertiesPart); } + else + { + if (document.CustomFilePropertiesPart != null) + document.DeletePart(document.CustomFilePropertiesPart); + } SetPackageProperties(document); // Clear list of deleted worksheets to prevent errors on multiple saves @@ -1749,10 +1754,10 @@ themePart.Theme = theme1; } - private void GenerateCustomFilePropertiesPartContent(CustomFilePropertiesPart customFilePropertiesPart1) + private void GenerateCustomFilePropertiesPartContent(CustomFilePropertiesPart customFilePropertiesPart) { - var properties2 = new DocumentFormat.OpenXml.CustomProperties.Properties(); - properties2.AddNamespaceDeclaration("vt", + var properties = new DocumentFormat.OpenXml.CustomProperties.Properties(); + properties.AddNamespaceDeclaration("vt", "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"); var propertyId = 1; foreach (var p in CustomProperties) @@ -1792,10 +1797,10 @@ var vTBool1 = new VTBool { Text = p.GetValue().ToString().ToLower() }; customDocumentProperty.AppendChild(vTBool1); } - properties2.AppendChild(customDocumentProperty); + properties.AppendChild(customDocumentProperty); } - customFilePropertiesPart1.Properties = properties2; + customFilePropertiesPart.Properties = properties; } private void SetPackageProperties(OpenXmlPackage document) diff --git a/ClosedXML_Tests/Resource/Examples/Misc/WorkbookProperties.xlsx b/ClosedXML_Tests/Resource/Examples/Misc/WorkbookProperties.xlsx index d9fba2c..969d71b 100644 --- a/ClosedXML_Tests/Resource/Examples/Misc/WorkbookProperties.xlsx +++ b/ClosedXML_Tests/Resource/Examples/Misc/WorkbookProperties.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/PivotTableReferenceFiles/PivotTableWithNoneTheme/outputfile.xlsx b/ClosedXML_Tests/Resource/Other/PivotTableReferenceFiles/PivotTableWithNoneTheme/outputfile.xlsx index be50146..309b880 100644 --- a/ClosedXML_Tests/Resource/Other/PivotTableReferenceFiles/PivotTableWithNoneTheme/outputfile.xlsx +++ b/ClosedXML_Tests/Resource/Other/PivotTableReferenceFiles/PivotTableWithNoneTheme/outputfile.xlsx Binary files differ diff --git a/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx index 6953f33..8619a59 100644 --- a/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx +++ b/ClosedXML_Tests/Resource/Other/StyleReferenceFiles/TransparentBackgroundFill/TransparentBackgroundFill.xlsx Binary files differ