Table extends Component { public List<Column> getColumnList() { ArrayList<Column> list = new ArrayList<Column>(); TableTableColumnElement colEle = null; for (Node n : new DomNodeList(mTableElement.getChildNodes())) { if (n instanceof TableTableHeaderColumnsElement) { TableTableHeaderColumnsElement headers = (TableTableHeaderColumnsElement) n; for (Node m : new DomNodeList(headers.getChildNodes())) { if (m instanceof TableTableColumnElement) { colEle = (TableTableColumnElement) m; int columnsRepeatedNumber = colEle.getTableNumberColumnsRepeatedAttribute(); for (int i = 0; i < columnsRepeatedNumber; i++) { list.add(getColumnInstance(colEle, i)); } } } } if (n instanceof TableTableColumnElement) { colEle = (TableTableColumnElement) n; int columnsRepeatedNumber = colEle.getTableNumberColumnsRepeatedAttribute(); for (int i = 0; i < columnsRepeatedNumber; i++) { list.add(getColumnInstance(colEle, i)); } } } return list; } 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 testGetColumnList() { String tablename = "MyTable"; String testFileName = "TestGetColumnList.odt"; try { TextDocument document = TextDocument.newTextDocument(); int rowcount = 3, columncount = 3; String[][] data = new String[rowcount][columncount]; for (int i = 0; i < rowcount; i++) { for (int j = 0; j < columncount; j++) { data[i][j] = "string" + (i * columncount + j); } } String[] rowlabels = new String[rowcount]; for (int i = 0; i < rowcount; i++) { rowlabels[i] = "RowHeader" + i; } String[] columnlabels = new String[columncount]; for (int i = 0; i < columncount; i++) { columnlabels[i] = "ColumnHeader" + i; } Table table3 = Table.newTable(document, rowlabels, columnlabels, data); table3.setTableName(tablename); document.save(ResourceUtilities.newTestOutputFile(testFileName)); document = loadODTDocument(testFileName); Table table = document.getTableByName(tablename); Column tmpColumn; List<Column> columns = table.getColumnList(); for (int i = 0; i < columns.size(); i++) { tmpColumn = columns.get(i); for (int j = 0; j < tmpColumn.getCellCount(); j++) { String text = tmpColumn.getCellByIndex(j).getStringValue(); if (i == 0 && j == 0) { Assert.assertEquals("", text); } else if (i == 0 && j > 0) { Assert.assertEquals("RowHeader" + (j - 1), text); } else if (i > 0 && j == 0) { Assert.assertEquals("ColumnHeader" + (i - 1), text); } else { Assert.assertEquals("string" + ((j - 1) * columncount + i - 1), text); } } } for (int i = 1; i < columns.size(); i++) { tmpColumn = columns.get(i); Assert.assertEquals(columnlabels[i - 1], tmpColumn.getCellByIndex(0).getStringValue()); } Assert.assertEquals(columncount, columns.size() - 1); Assert.assertEquals("", columns.get(0).getCellByIndex(0).getStringValue()); Iterator<Column> columnIterator = table.getColumnIterator(); int columnNumber =0; if(columnIterator.hasNext()){ Column column = columnIterator.next(); Assert.assertEquals("", column.getCellByIndex(0).getStringValue()); columnNumber++; } while(columnIterator.hasNext()){ Column column = columnIterator.next(); Assert.assertEquals(columnlabels[columnNumber-1], column.getCellByIndex(0).getStringValue()); columnNumber++; } Assert.assertEquals(columnNumber, columns.size()); } catch (Exception e) { Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, e); Assert.fail(e.getMessage()); } }