在加载Excel文件时解析透视缓存记录
可能的使用场景
创建透视表时,Microsoft Excel会复制源数据并将其存储在透视缓存中。透视缓存保存在Microsoft Excel的内存中。您看不到它,但这是建立透视表、更改切片选择或移动行/列时透视表引用的数据。这使得Microsoft Excel能够对透视表的更改做出非常灵敏的响应,但它也可能使文件的大小翻倍。毕竟,透视缓存只是源数据的副本,因此您的文件大小可能会翻倍。
在加载Excel文件时,您可以使用LoadOptions.ParsingPivotCachedRecords属性来决定是否同时加载数据透视缓存记录。这个属性的默认值是false。如果数据透视缓存相当大,它可以提高性能。但如果您也想加载数据透视缓存记录,您应该将此属性设置为true。
在加载Excel文件时解析透视缓存记录
以下示例代码解释了使用LoadOptions.ParsingPivotCachedRecords属性的用法。它在解析数据透视缓存记录时加载了示例Excel文件。然后刷新数据透视表并将其保存为输出Excel文件。
示例代码
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Create load options | |
LoadOptions options = new LoadOptions(); | |
//Set ParsingPivotCachedRecords true, default value is false | |
options.setParsingPivotCachedRecords(true); | |
//Load the sample Excel file containing pivot table cached records | |
Workbook wb = new Workbook("sampleParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx", options); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access first pivot table | |
PivotTable 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"); |