Excelファイルをロードする際にPivotキャッシュレコードを解析する

可能な使用シナリオ

Pivot Tableを作成する際に、Microsoft Excelは元のデータのコピーを取り、それをPivot Cacheに保存します。Pivot CacheはMicrosoft Excelのメモリ内に保持されます。それを見ることはできませんが、それがPivot Tableが構築されたりSlicerの選択が変更されたり行または列が移動されたりするときに参照するデータです。これにより、Microsoft ExcelはPivot Tableの変更に非常に敏感になりますが、ファイルのサイズが2倍になる可能性もあります。つまり、Pivot Cacheはソースデータの単なるコピーなので、ファイルサイズが潜在的に2倍になるのは理にかなっています。

Workbookオブジェクト内にExcelファイルをロードするときに、Pivot Cacheのレコードも一緒に読み込むかどうかをLoadOptions.parsing_pivot_cached_recordsプロパティを使用して決定できます。このプロパティのデフォルト値はfalseです。Pivot Cacheがかなり大きい場合、パフォーマンスが向上することがあります。しかし、Pivot Cacheのレコードも読み込む場合は、このプロパティをtrueに設定する必要があります。

Excelファイルを読み込む際のPivot Cached Recordsのパーシング方法

以下のサンプルコードは、LoadOptions.parsing_pivot_cached_recordsプロパティの使用方法を説明します。それはPivot Cacheのレコードを解析しながらサンプル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")