SpreadsheetDocument extends Document implements ChartContainer { public void removeSheet(int index) { if (index < 0) { return; } int count = 0; try { OfficeSpreadsheetElement spreadsheetElement = getContentRoot(); Node child = spreadsheetElement.getFirstChild(); while ((child != null) && (count <= index)) { if (child instanceof TableTableElement) { if (count == index) { spreadsheetElement.removeChild(child); return; } else { count++; } } child = child.getNextSibling(); } } catch (Exception e) { Logger.getLogger(SpreadsheetDocument.class.getName()).log(Level.SEVERE, null, e); } } protected  SpreadsheetDocument(OdfPackage pkg, String internalPath, SpreadsheetDocument.OdfMediaType odfMediaType); static SpreadsheetDocument newSpreadsheetDocument(); static SpreadsheetDocument newSpreadsheetTemplateDocument(); static SpreadsheetDocument loadDocument(InputStream inputStream); static SpreadsheetDocument loadDocument(String documentPath); static SpreadsheetDocument loadDocument(File file); @Override OfficeSpreadsheetElement getContentRoot(); void changeMode(OdfMediaType mediaType); Table getSheetByIndex(int index); Table getSheetByName(String name); Table getActiveSheet(); Table appendSheet(String name); Table appendSheet(Table refTable, String name); Table insertSheet(int before); Table insertSheet(Table refTable, int before); void removeSheet(int index); int getSheetCount(); OdfElement getTableContainerElement(); Chart createChart(String title, DataSet dataset, Rectangle rect); Chart createChart(String title, SpreadsheetDocument document, CellRangeAddressList cellRangeAddr, boolean firstRowAsLabel,
        boolean firstColumnAsLabel, boolean rowAsDataSeries, Rectangle rect); Chart createChart(String title, String[] labels, String[] legends, double[][] data, Rectangle rect); Chart createChart(String title, SpreadsheetDocument document, CellRangeAddressList cellRangeAddr, boolean firstRowAsLabel,
        boolean firstColumnAsLabel, boolean rowAsDataSeries, Rectangle rect, Cell cell); void deleteChartById(String chartId); void deleteChartByTitle(String title); Chart getChartById(String chartId); List<Chart> getChartByTitle(String title); int getChartCount();  }
@Test public void testRemoveSheet() throws Exception{ File file = new File(ResourceUtilities.getAbsolutePath(TEST_FILE)); SpreadsheetDocument spDocument = SpreadsheetDocument.loadDocument(file); Table table = spDocument.insertSheet(-1); Assert.assertNull(table); Table tableb = spDocument.insertSheet(11); Assert.assertNull(tableb); Table tab = spDocument.getSheetByName("tabellDemo2"); if(tab != null){ for(int i=0;i<spDocument.getSheetCount();i++){ if(tab.equals(spDocument.getSheetByIndex(i))) spDocument.removeSheet(i); } } Table tablea = spDocument.insertSheet(0); Column col = tablea.appendColumn(); col.setWidth(12.99); Column col2 = tablea.appendColumn(); col.setWidth(12.); tablea.setTableName("tabellDemo2"); Assert.assertEquals("tabellDemo2", tablea.getTableName()); spDocument.removeSheet(0); Table tablem = spDocument.getSheetByIndex(0); Assert.assertNotSame(tablea, tablem); spDocument.save(ResourceUtilities.getAbsolutePath(TEST_FILE)); }