diff --git a/ClosedXML/Excel/PivotTables/IXLPivotTable.cs b/ClosedXML/Excel/PivotTables/IXLPivotTable.cs index 03f76d1..027dd94 100644 --- a/ClosedXML/Excel/PivotTables/IXLPivotTable.cs +++ b/ClosedXML/Excel/PivotTables/IXLPivotTable.cs @@ -107,7 +107,7 @@ IXLPivotFields Fields { get; } IXLPivotFields ReportFilters { get; } - IXLPivotFields ColumnLabels { get; } + IXLPivotFields ColumnLabels { get; } IXLPivotFields RowLabels { get; } IXLPivotValues Values { get; } @@ -115,6 +115,9 @@ String Title { get; set; } String Description { get; set; } + String ColumnHeaderCaption { get; set; } + String RowHeaderCaption { get; set; } + IXLCell TargetCell { get; set; } IXLRange SourceRange { get; set; } @@ -196,6 +199,9 @@ IXLPivotTable SetItemsToRetainPerField(XLItemsToRetain value); IXLPivotTable SetEnableCellEditing(); IXLPivotTable SetEnableCellEditing(Boolean value); + IXLPivotTable SetColumnHeaderCaption(String value); + IXLPivotTable SetRowHeaderCaption(String value); + Boolean ShowRowHeaders { get; set; } Boolean ShowColumnHeaders { get; set; } Boolean ShowRowStripes { get; set; } diff --git a/ClosedXML/Excel/PivotTables/XLPivotTable.cs b/ClosedXML/Excel/PivotTables/XLPivotTable.cs index e1232cb..6e7c1f0 100644 --- a/ClosedXML/Excel/PivotTables/XLPivotTable.cs +++ b/ClosedXML/Excel/PivotTables/XLPivotTable.cs @@ -38,6 +38,20 @@ public String Title { get; set; } public IXLPivotTable SetTitle(String value) { Title = value; return this; } public String Description { get; set; } public IXLPivotTable SetDescription(String value) { Description = value; return this; } + public String ColumnHeaderCaption { get; set; } + public IXLPivotTable SetColumnHeaderCaption(String value) + { + ColumnHeaderCaption = value; + return this; + } + + public String RowHeaderCaption { get; set; } + public IXLPivotTable SetRowHeaderCaption(String value) + { + RowHeaderCaption = value; + return this; + } + public Boolean MergeAndCenterWithLabels { get; set; } public IXLPivotTable SetMergeAndCenterWithLabels() { MergeAndCenterWithLabels = true; return this; } public IXLPivotTable SetMergeAndCenterWithLabels(Boolean value) { MergeAndCenterWithLabels = value; return this; } public Int32 RowLabelIndent { get; set; } public IXLPivotTable SetRowLabelIndent(Int32 value) { RowLabelIndent = value; return this; } public XLFilterAreaOrder FilterAreaOrder { get; set; } public IXLPivotTable SetFilterAreaOrder(XLFilterAreaOrder value) { FilterAreaOrder = value; return this; } diff --git a/ClosedXML/Excel/XLWorkbook_Load.cs b/ClosedXML/Excel/XLWorkbook_Load.cs index f2080c5..549357b 100644 --- a/ClosedXML/Excel/XLWorkbook_Load.cs +++ b/ClosedXML/Excel/XLWorkbook_Load.cs @@ -478,6 +478,13 @@ if (target != null && source != null) { var pt = ws.PivotTables.AddNew(pivotTableDefinition.Name, target, source) as XLPivotTable; + + if (!String.IsNullOrWhiteSpace(StringValue.ToString(pivotTableDefinition?.ColumnHeaderCaption ?? String.Empty))) + pt.SetColumnHeaderCaption(StringValue.ToString(pivotTableDefinition.ColumnHeaderCaption)); + + if (!String.IsNullOrWhiteSpace(StringValue.ToString(pivotTableDefinition?.RowHeaderCaption ?? String.Empty))) + pt.SetRowHeaderCaption(StringValue.ToString(pivotTableDefinition.RowHeaderCaption)); + pt.RelId = wsPart.GetIdOfPart(pivotTablePart); pt.CacheDefinitionRelId = pivotTablePart.GetIdOfPart(pivotTableCacheDefinitionPart); pt.WorkbookCacheRelId = dSpreadsheet.WorkbookPart.GetIdOfPart(pivotTableCacheDefinitionPart); diff --git a/ClosedXML/Excel/XLWorkbook_Save.cs b/ClosedXML/Excel/XLWorkbook_Save.cs index 9e8f1a1..d80ed6f 100644 --- a/ClosedXML/Excel/XLWorkbook_Save.cs +++ b/ClosedXML/Excel/XLWorkbook_Save.cs @@ -2060,6 +2060,12 @@ EnableDrill = OpenXmlHelper.GetBooleanValue(pt.EnableShowDetails, true) }; + if (!String.IsNullOrEmpty(pt.ColumnHeaderCaption)) + pivotTableDefinition.ColumnHeaderCaption = StringValue.FromString(pt.ColumnHeaderCaption); + + if (!String.IsNullOrEmpty(pt.RowHeaderCaption)) + pivotTableDefinition.RowHeaderCaption = StringValue.FromString(pt.RowHeaderCaption); + if (pt.ClassicPivotTableLayout) { pivotTableDefinition.Compact = false; diff --git a/ClosedXML_Examples/PivotTables/PivotTables.cs b/ClosedXML_Examples/PivotTables/PivotTables.cs index fa479da..a94bb10 100644 --- a/ClosedXML_Examples/PivotTables/PivotTables.cs +++ b/ClosedXML_Examples/PivotTables/PivotTables.cs @@ -110,6 +110,8 @@ pt.Values.Add("NumberOfOrders").SetSummaryFormula(XLPivotSummary.Sum); pt.Values.Add("Quality").SetSummaryFormula(XLPivotSummary.Sum); + pt.SetRowHeaderCaption("Pastry name"); + #endregion Different kind of pivot #region Pivot table with collapsed fields @@ -162,6 +164,8 @@ pt.Subtotals = XLPivotSubtotals.DoNotShow; + pt.SetColumnHeaderCaption("Measures"); + ptSheet.Columns().AdjustToContents(); #endregion Pivot table with subtotals disabled diff --git a/ClosedXML_Tests/Resource/Examples/PivotTables/PivotTables.xlsx b/ClosedXML_Tests/Resource/Examples/PivotTables/PivotTables.xlsx index 369bb0c..247daba 100644 --- a/ClosedXML_Tests/Resource/Examples/PivotTables/PivotTables.xlsx +++ b/ClosedXML_Tests/Resource/Examples/PivotTables/PivotTables.xlsx Binary files differ