Parsing Pivot Cached Records while loading Excel file
Possible Usage Scenarios
When you create a Pivot Table, Microsoft Excel takes a copy of the source data and stores it in the Pivot Cache. The Pivot Cache is held inside the memory of Microsoft Excel. You cannot see it but that is the data the Pivot Table references when you build your Pivot Table or change a Slicer selection or move rows/columns around. This enables Microsoft Excel to be very responsive to changes in the Pivot Table but it can also double the size of your file. After all, the Pivot Cache is just a duplicate of your source data so it makes sense that your file size will be potentially double.
When you load your Excel file inside the Workbook object, you can decide whether you also want to load the records of Pivot Cache or not, using the LoadOptions.setParsingPivotCachedRecords property. The default value of this property is false. If Pivot Cache is quite big, it can increase the performance. But if you also want to load the records of Pivot Cache, you should set this property as true.
Parsing Pivot Cached Records while loading Excel file
The following sample code explains the usage of LoadOptions.setParsingPivotCachedRecords property. It loads the sample Excel file while parsing the pivot cached records. Then it refreshes the pivot table and saves it as the output Excel file.
Sample Code
const AsposeCells = require("aspose.cells.node"); | |
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
//Create load options | |
var options = new AsposeCells.LoadOptions(); | |
//Set ParsingPivotCachedRecords true, default value is false | |
options.setParsingPivotCachedRecords(true); | |
//Load the sample Excel file containing pivot table cached records | |
var wb = new AsposeCells.Workbook("sampleParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx", options); | |
//Access first worksheet | |
var ws = wb.getWorksheets().get(0); | |
//Access first pivot table | |
var pt = ws.getPivotTables().get(0); | |
//Set refresh data flag true | |
pt.setRefreshDataFlag(true); | |
//Refresh and calculate pivot table | |
pt.refreshData(); | |
pt.calculateData(); | |
//Set refresh data flag false | |
pt.setRefreshDataFlag(false); | |
//Save the output Excel file | |
wb.save("outputParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx"); |