在加载Excel文件时解析透视缓存记录
可能的使用场景
创建透视表时,Microsoft Excel会复制源数据并将其存储在透视缓存中。透视缓存保存在Microsoft Excel的内存中。您看不到它,但这是建立透视表、更改切片选择或移动行/列时透视表引用的数据。这使得Microsoft Excel能够对透视表的更改做出非常灵敏的响应,但它也可能使文件的大小翻倍。毕竟,透视缓存只是源数据的副本,因此您的文件大小可能会翻倍。
在将Excel文件加载到Workbook对象中时,您可以决定是否也要加载透视缓存记录,使用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-.NET | |
//Create load options | |
LoadOptions options = new LoadOptions(); | |
//Set ParsingPivotCachedRecords true, default value is false | |
options.ParsingPivotCachedRecords = true; | |
//Load the sample Excel file containing pivot table cached records | |
Workbook wb = new Workbook("sampleParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx", options); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access first pivot table | |
PivotTable pt = ws.PivotTables[0]; | |
//Set refresh data flag true | |
pt.RefreshDataFlag = true; | |
//Refresh and calculate pivot table | |
pt.RefreshData(); | |
pt.CalculateData(); | |
//Set refresh data flag false | |
pt.RefreshDataFlag = false; | |
//Save the output Excel file | |
wb.Save("outputParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx"); |