Delete Pivot Table from a Worksheet

Contents
[ ]

Example

The following sample code deletes two pivot tables from the worksheet. First, it removes the pivot table using Worksheet.getPivotTables().remove() method and then it removes the pivot table using Worksheet.getPivotTables().removeAt() method

// 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");