thanks Amjad,
I’m having a few trouble points with a pivot table and I think I’m not updating the pivot table datasource correctly.
I’ve created a test project and if I ChangeDataSource as below the slicers disappears from the first pivot table/Pivot1 (see attached). Also the pivot table name/reference is not longer visible from the slicers on Pivot 2.
var workbook = new Workbook(pathToFile);
var cellsMaxDisplayRange = workbook.Worksheets["Data_Reports"].Cells.MaxDisplayRange;
var dataWorksheetRefersTo = cellsMaxDisplayRange.RefersTo;
var pivotSheets = new List<string> { "Pivot1", "Pivot2" };
foreach (var name in pivotSheets)
{
var pivotSheet = workbook.Worksheets[name];
foreach (var pt in pivotSheet.PivotTables)
{
pt.ChangeDataSource(new[] { dataWorksheetRefersTo });
pt.RefreshData();
pt.CalculateData();
}
}
var newFile = Path.Combine(pathToNewFile);
workbook.Save(newFile);
The documentation I can find (https://docs.aspose.com/display/cellsnet/Pivot+Table+and+Source+Data#PivotTableandSourceData-ChangingaPivotTable’sSourceData) refer to a named range as a datasource.
Could you by any change correct the code block above to the correct way of updating the pivot table datasource?
Thanks in advance
Best regards Morten