ピボットテーブルを更新し計算項目を持つピボットテーブルを更新する
Contents
[
Hide
]
Aspose.Cellsは、計算アイテムを持つピボットテーブルのリフレッシュと計算をサポートしています。この機能を実行するには、通常通りPivotTable.refreshData()とPivotTable.caclulateData()を使用してください。
計算項目を持つピボットテーブルを更新および計算する
以下のサンプルコードは、“add”、“div”、“div2"などの3つの計算アイテムを持つピボットテーブルを含むソースExcelファイルを読み込みます。まず、セル D2 の値を20に変更し、その後、Aspose.CellsのAPIを使用してピボットテーブルをリフレッシュおよび計算し、ワークブックをPDF形式で保存します。出力PDFの結果は、Aspose.Cellsが計算アイテムを持つピボットテーブルを正常にリフレッシュおよび計算したことを示しています。手動でセルD2に値20を入力し、Alt+F5ショートカットキーを使用するか、ピボットテーブルのリフレッシュボタンをクリックして、Microsoft Excelで検証できます。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RefreshCalculatePivotTablehavingCalculatedItems.class); | |
// Load source excel file containing a pivot table having calculated | |
// items | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Change the value of cell D2 | |
sheet.getCells().get("D2").putValue(20); | |
// Refresh and calculate all the pivot tables inside this sheet | |
for (int i = 0; i < sheet.getPivotTables().getCount(); i++) { | |
PivotTable pt = sheet.getPivotTables().get(i); | |
pt.refreshData(); | |
pt.calculateData(); | |
} | |
// Save the workbook in output pdf | |
wb.save(dataDir + "output.pdf", SaveFormat.PDF); |