ワークシートからのピボットテーブルの削除

Contents
[ ]

次のサンプルコードは、ワークシートから2つのピボットテーブルを削除します。最初に、Worksheet.getPivotTables().remove()メソッドを使用してピボットテーブルを削除し、次に、Worksheet.getPivotTables().removeAt()メソッドを使用してピボットテーブルを削除します。

// 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(DeletePivotTableFromWorksheet.class);
// Create workbook object from source Excel file
Workbook workbook = new Workbook(dataDir + "sample.xlsx");
// Access the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Access the first pivot table object
PivotTable pivotTable = worksheet.getPivotTables().get(0);
// Remove pivot table using pivot table object
worksheet.getPivotTables().remove(pivotTable);
// Remove pivot table using pivot table position
worksheet.getPivotTables().removeAt(0);
// Save the workbook
workbook.save(dataDir + "output.xlsx");