Table extends Component { public Cell getCellByPosition(int colIndex, int rowIndex) { if (colIndex < 0 || rowIndex < 0) { throw new IllegalArgumentException("colIndex and rowIndex should be nonnegative integer."); } int lastRowIndex = getRowCount() - 1; if (rowIndex > lastRowIndex) { appendRows((rowIndex - lastRowIndex), true); } int lastColumnIndex = getColumnCount() - 1; if (colIndex > lastColumnIndex) { appendColumns((colIndex - lastColumnIndex), true); } Row row = getRowByIndex(rowIndex); return row.getCellByIndex(colIndex); } 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 testGetCellByPosition() { testNewTable(); mOdtDoc = loadODTDocument("CreateTableCase.odt"); Table table = mOdtDoc.getTableByName("Table3"); Cell cell = table.getCellByPosition(3, 3); Assert.assertNotNull(cell); Assert.assertEquals("string12", cell.getStringValue()); cell = table.getCellByPosition("D4"); Assert.assertNotNull(cell); Assert.assertEquals("string12", cell.getStringValue()); boolean illegalArgumentFlag = false; try { cell = table.getCellByPosition(-1, 0); } catch (IllegalArgumentException ie) { if ("colIndex and rowIndex should be nonnegative integer.".equals(ie.getMessage())) { illegalArgumentFlag = true; } } Assert.assertTrue(illegalArgumentFlag); cell = table.getCellByPosition(8, 6); Assert.assertNotNull(cell); cell.setStringValue("string86"); Assert.assertEquals("string86", cell.getStringValue()); cell = table.getCellByPosition(4, 9); Assert.assertNotNull(cell); cell.setStringValue("string49"); Assert.assertEquals("string49", cell.getStringValue()); cell = table.getCellByPosition(9, 10); Assert.assertNotNull(cell); cell.setStringValue("string910"); Assert.assertEquals("string910", cell.getStringValue()); cell = table.getCellByPosition("I4"); Assert.assertNotNull(cell); cell.setStringValue("stringI4"); Assert.assertEquals("stringI4", cell.getStringValue()); cell = table.getCellByPosition("D11"); Assert.assertNotNull(cell); cell.setStringValue("stringD11"); Assert.assertEquals("stringD11", cell.getStringValue()); cell = table.getCellByPosition("K12"); Assert.assertNotNull(cell); cell.setStringValue("stringK12"); Assert.assertEquals("stringK12", cell.getStringValue()); table = mOdsDoc.getTableByName("Sheet1"); cell = table.getCellByPosition("C1"); Assert.assertNotNull(cell); Assert.assertEquals("Currency", cell.getStringValue()); cell = table.getCellByPosition("K4"); Assert.assertNotNull(cell); cell.setBooleanValue(true); Assert.assertEquals(Boolean.TRUE, cell.getBooleanValue()); cell = table.getCellByPosition("D10"); Assert.assertNotNull(cell); Calendar cal = Calendar.getInstance(); cell.setTimeValue(cal); SimpleDateFormat simpleFormat = new SimpleDateFormat("'PT'HH'H'mm'M'ss'S'"); String expectedString = simpleFormat.format(cal.getTime()); String targetString = simpleFormat.format(cell.getTimeValue().getTime()); Assert.assertEquals(expectedString, targetString); cell = table.getCellByPosition("M15"); Assert.assertNotNull(cell); cell.setStringValue("stringM15"); Assert.assertEquals("stringM15", cell.getStringValue()); }