計算項目を含むピボット テーブルの更新と計算
Contents
[
Hide
]
Aspose.Cells は、計算項目を持つピボット テーブルの更新と計算をサポートするようになりました。使ってください[PivotTable.refreshData()](https://reference.aspose.com/cells/java/com.aspose.cells/pivottable#refreshData() ) とPivotTable.caclulateData() 通常どおり、この機能を実行します。
計算項目を含むピボット テーブルの更新と計算
次のサンプル コードは、ソースエクセルファイル「add」、「div」、「div2」などの 3 つの計算項目を持つピボット テーブルが含まれています。最初にセル D2 の値を 20 に変更し、Aspose.Cells API を使用してピボット テーブルを更新して計算し、ワークブックを PDF 形式で保存します。での結果出力 PDFAspose.Cells が、計算項目を含むピボット テーブルを更新して計算したことを示しています。 Microsoft Excel を使用してセル D2 に値 20 を手動で入力し、Alt+F5 ショートカット キーを使用してピボット テーブルを更新するか、ピボット テーブルの [更新] ボタンをクリックして確認できます。
This file contains hidden or 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); |