I can easily create two Worksheets, and I can easily add a Pivot Table to one of the worksheets. But if you try to add a second Pivot Table to the second Worksheet, you end up with a corrupted excel document.
Below is the method I am calling. It works great once, but not twice.
When I call this method, wsPivot is a new worksheet. I have tried using a different dataRange, or the same dataRange, but either way fails. The new worksheets are there, and work without issue if I don't add a pivot table to them.
I will try to dive into the XML to find the problem, but that is as we all know challenging. Hope somebody has a work around, I really need this fix to continue using this library. Thanks.
private static void CreatePivotTable(IXLRange dataRange, IXLWorksheet wsPivot, string pivotTableName)
{
var pt = wsPivot.CreatePivotTable(wsPivot.Cell(3, 1), pivotTableName);
pt.SourceRange = dataRange;
// OR
// var pt = wsPivot.PivotTables.AddNew(pivotTableName, wsPivot.Cell(3, 1), dataRange);
pt.RowLabels.Add("UnitNames");
pt.Values.Add("TotalPrice").SetSummaryFormula(XLPivotSummary.Sum);
}
Below is the method I am calling. It works great once, but not twice.
When I call this method, wsPivot is a new worksheet. I have tried using a different dataRange, or the same dataRange, but either way fails. The new worksheets are there, and work without issue if I don't add a pivot table to them.
I will try to dive into the XML to find the problem, but that is as we all know challenging. Hope somebody has a work around, I really need this fix to continue using this library. Thanks.
private static void CreatePivotTable(IXLRange dataRange, IXLWorksheet wsPivot, string pivotTableName)
{
var pt = wsPivot.CreatePivotTable(wsPivot.Cell(3, 1), pivotTableName);
pt.SourceRange = dataRange;
// OR
// var pt = wsPivot.PivotTables.AddNew(pivotTableName, wsPivot.Cell(3, 1), dataRange);
pt.RowLabels.Add("UnitNames");
pt.Values.Add("TotalPrice").SetSummaryFormula(XLPivotSummary.Sum);
}