Table extends Component { public Row getRowByIndex(int index) { if (index < 0) { throw new IllegalArgumentException("index should be nonnegative integer."); } int lastIndex = getRowCount() - 1; if (index > lastIndex) { appendRows(index - lastIndex); } int result = 0; Row row = null; for (Node n : new DomNodeList(mTableElement.getChildNodes())) { if (n instanceof TableTableHeaderRowsElement) { row = getHeaderRowByIndex((TableTableHeaderRowsElement) n, index); if (row != null) { return row; } result += getHeaderRowCount((TableTableHeaderRowsElement) n); } if (n instanceof TableTableRowElement) { row = getRowInstance((TableTableRowElement) n, 0); result += row.getRowsRepeatedNumber(); } if (n instanceof TableTableRowsElement) { for (Node nn : new DomNodeList(n.getChildNodes())) { if (nn instanceof TableTableRowElement) { row = getRowInstance((TableTableRowElement) nn, 0); result += row.getRowsRepeatedNumber(); if (result > index) { return getRowInstance(row.getOdfElement(), index - (result - row.getRowsRepeatedNumber())); } } } } if (result > index) { return getRowInstance(row.getOdfElement(), index - (result - row.getRowsRepeatedNumber())); } } return null; } private  Table(TableContainer container, TableTableElement table); static Table getInstance(TableTableElement element); static Table newTable(TableContainer tableContainer); static Table newTable(TableContainer tableContainer, int numRows, int numCols); static Table newTable(TableContainer tableContainer, int numRows, int numCols, 
			double marginLeft, double marginRight); static Table newTable(TableContainer tableContainer, int numRows, int numCols, int headerRowNumber,
			int headerColumnNumber); static Table newTable(TableContainer tableContainer, String[] rowLabel, String[] columnLabel, double[][] data); static Table newTable(TableContainer tableContainer, String[] rowLabel, String[] columnLabel, String[][] data); double getWidth(); void setWidth(double width); void applyStyle(TableTemplate template); int getRowCount(); int getColumnCount(); Row appendRow(); List<Row> appendRows(int rowCount); Column appendColumn(); List<Column> appendColumns(int columnCount); TableTableElement getOdfElement(); List<Column> insertColumnsBefore(int index, int columnCount); void removeColumnsByIndex(int startIndex, int deleteColCount); List<Row> insertRowsBefore(int index, int rowCount); List<Column> getColumnList(); Iterator<Column> getColumnIterator(); List<Row> getRowList(); Iterator<Row> getRowIterator(); Column getColumnByIndex(int index); Row getRowByIndex(int index); void removeRowsByIndex(int startIndex, int deleteRowCount); void remove(); int getHeaderRowCount(); int getHeaderColumnCount(); String getTableName(); void setTableName(String tableName); boolean isProtected(); void setProtected(boolean isProtected); boolean isCellStyleInheritance(); void setCellStyleInheritance(boolean isEnabled); boolean isUseRepeat(); void setUseRepeat(boolean isSingle); CellRange getCellRangeByPosition(int startCol, int startRow, int endCol, int endRow); CellRange getCellRangeByPosition(String startAddress, String endAddress); CellRange getCellRangeByName(String name); Cell getCellByPosition(int colIndex, int rowIndex); Cell getCellByPosition(String address); void setVerticalMargin(double spaceTop, double spaceBottom); DefaultStyleHandler getStyleHandler();  }
@Test public void testGetRowByIndex() { testNewTable(); mOdtDoc = loadODTDocument("CreateTableCase.odt"); Table table = mOdtDoc.getTableByName("Table3"); Assert.assertNotNull(table); boolean illegalArgumentFlag = false; try { table.getRowByIndex(-1); } catch (IllegalArgumentException ie) { if ("index should be nonnegative integer.".equals(ie.getMessage())) { illegalArgumentFlag = true; } } Assert.assertTrue(illegalArgumentFlag); Row row = table.getRowByIndex(3); Assert.assertNotNull(row); Assert.assertEquals("string12", row.getCellByIndex(3).getStringValue()); row = table.getRowByIndex(6); Assert.assertNotNull(row); Cell cell = row.getCellByIndex(8); Assert.assertNotNull(cell); cell.setStringValue("string86"); Assert.assertEquals("string86", cell.getStringValue()); }
@Test public void testGetCellAt() { try { SpreadsheetDocument doc = (SpreadsheetDocument) SpreadsheetDocument.loadDocument(ResourceUtilities .getTestResourceAsStream("testGetCellAt.ods")); Table odfTable = doc.getTableList().get(0); Row valueRows = odfTable.getRowByIndex(0); for (int i = 0; i < 4; i++) { Cell cell = valueRows.getCellByIndex(i); Assert.assertNotNull(cell); int value = cell.getDoubleValue().intValue(); Assert.assertEquals(1, value); } } catch (Exception e) { Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e); } }