SpreadsheetDocument extends Document implements ChartContainer { public Table getSheetByIndex(int index) { if (index < 0) { return null; } int count = 0; try { OfficeSpreadsheetElement spreadsheetElement = getContentRoot(); Node child = spreadsheetElement.getFirstChild(); while ((child != null) && (count <= index)) { if (child instanceof TableTableElement) { if (count == index) { return getTableBuilder().getTableInstance((TableTableElement) child); } else { count++; } } child = child.getNextSibling(); } } catch (Exception e) { Logger.getLogger(SpreadsheetDocument.class.getName()).log(Level.SEVERE, null, e); } return null; } 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 testGetSheetByIndex() throws Exception{ File file = new File(ResourceUtilities.getAbsolutePath("TestSpreadsheetTable.ods")); SpreadsheetDocument spDocument = SpreadsheetDocument.loadDocument(file); Table tablenull = spDocument.getSheetByIndex(-1); Assert.assertTrue((tablenull == null)); Table tableSheet0 = spDocument.getSheetByIndex(0); Assert.assertTrue((tableSheet0 != null)); Assert.assertEquals("Sheet1", tableSheet0.getTableName()); Assert.assertEquals(29, tableSheet0.getColumnCount()); Table tableSheet1 = spDocument.getSheetByIndex(1); Assert.assertTrue((tableSheet1 != null)); Assert.assertEquals("Sheet2", tableSheet1.getTableName()); Assert.assertEquals(1, tableSheet1.getColumnCount()); }