在加载Excel文件时解析透视缓存记录
可能的使用场景
创建透视表时,Microsoft Excel会复制源数据并将其存储在透视缓存中。透视缓存保存在Microsoft Excel的内存中。您看不到它,但这是建立透视表、更改切片选择或移动行/列时透视表引用的数据。这使得Microsoft Excel能够对透视表的更改做出非常灵敏的响应,但它也可能使文件的大小翻倍。毕竟,透视缓存只是源数据的副本,因此您的文件大小可能会翻倍。
在将Excel文件加载到Workbook对象中时,您可以决定是否也要加载透视缓存记录,使用LoadOptions.parsing_pivot_cached_records属性。此属性的默认值为false。如果透视缓存相当大,它会提高性能。但如果您也想加载透视缓存记录,应将此属性设置为true。
加载Excel文件时如何解析数据透视缓存记录
以下示例代码解释了LoadOptions.parsing_pivot_cached_records属性的用法。它在解析透视缓存记录时加载示例Excel文件。然后刷新透视表并将其保存为输出Excel文件。
示例代码
from aspose.cells import LoadOptions, Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create load options | |
options = LoadOptions() | |
# Set ParsingPivotCachedRecords true, default value is false | |
options.parsing_pivot_cached_records = True | |
# Load the sample Excel file containing pivot table cached records | |
wb = Workbook("sampleParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx", options) | |
# Access first worksheet | |
ws = wb.worksheets[0] | |
# Access first pivot table | |
pt = ws.pivot_tables[0] | |
# Set refresh data flag true | |
pt.refresh_data_flag = True | |
# Refresh and calculate pivot table | |
pt.refresh_data() | |
pt.calculate_data() | |
# Set refresh data flag false | |
pt.refresh_data_flag = False | |
# Save the output Excel file | |
wb.save("outputParsingPivotCachedRecordsWhileLoadingExcelFile.xlsx") |