/** * this method update column header of sheet into table * * @param ctTable * xssf table object * @param title * title of column * @param index * index of column */ private void updateSheetTable(CTTable ctTable, String title, int index) { CTTableColumns tableColumnList = ctTable.getTableColumns(); CTTableColumn column = null; for( int i = 0; tableColumnList.getCount() < index; i++) { column = tableColumnList.addNewTableColumn(); column.setId(i); } column = tableColumnList.getTableColumnArray(index); column.setName(title); }
/** * Remove a column from the table. * * @param columnIndex * the 0-based position of the column in the table * @throws IllegalArgumentException * if no column at the index exists or if the table has only a * single column * @since 4.0.0 */ public void removeColumn(int columnIndex) { if (columnIndex < 0 || columnIndex > getColumnCount() - 1) { throw new IllegalArgumentException("Column index out of bounds"); } if(getColumnCount() == 1) { throw new IllegalArgumentException("Table must have at least one column"); } CTTableColumns tableColumns = ctTable.getTableColumns(); tableColumns.removeTableColumn(columnIndex); tableColumns.setCount(tableColumns.getTableColumnList().size()); updateReferences(); updateHeaders(); }
CTTableColumn column = columns.insertNewTableColumn(columnIndex); columns.setCount(columns.sizeOfTableColumnArray());
for (int i = 0; i < ctColumns.getCount(); i++) { ctColumns.removeTableColumn(0); CTTableColumn column = ctColumns.addNewTableColumn(); column.setName(tableHeaders.get(i)); column.setId(i + 1); ctColumns.setCount(tableHeaders.size());
CTTableColumns ctColumns = ctTable.addNewTableColumns(); CTAutoFilter autofilter = ctTable.addNewAutoFilter(); ctColumns.setCount(table_headers.size()); for(int i = 0; i < table_headers.size(); i++) { CTTableColumn column = ctColumns.addNewTableColumn(); column.setName(table_headers.get(i)); column.setId(i + 1); CTFilterColumn filter = autofilter.addNewFilterColumn(); filter.setColId(i + 1); filter.setShowButton(true); }
/** * Get the total number of columns in this table. * * @return the column count * @since 4.0.0 */ public int getColumnCount() { CTTableColumns tableColumns = ctTable.getTableColumns(); if(tableColumns == null) { return 0; } // Casting to int should be safe here - tables larger than the // sheet (which holds the actual data of the table) can't exists. return (int) tableColumns.getCount(); }
/** * Note this list is static - once read, it does not notice later changes to the underlying column structures * To clear the cache, call {@link #updateHeaders} * @return List of XSSFTableColumn * @since 4.0.0 */ public List<XSSFTableColumn> getColumns() { if (tableColumns == null) { List<XSSFTableColumn> columns = new ArrayList<>(); CTTableColumns ctTableColumns = ctTable.getTableColumns(); if (ctTableColumns != null) { for (CTTableColumn column : ctTableColumns.getTableColumnList()) { XSSFTableColumn tableColumn = new XSSFTableColumn(this, column); columns.add(tableColumn); } } tableColumns = Collections.unmodifiableList(columns); } return tableColumns; }
for(CTTableColumn col : ctTable.getTableColumns().getTableColumnArray()){ String elementName = SST.toXMLEment(originalTable.getTableColumns().getTableColumnArray(i++).getName());
/** * Remove a column from the table. * * @param column * the column to remove * @since 4.0.0 */ public void removeColumn(XSSFTableColumn column) { int columnIndex = getColumns().indexOf(column); if (columnIndex >= 0) { ctTable.getTableColumns().removeTableColumn(columnIndex); updateReferences(); updateHeaders(); } }
columns.setCount(3L); //define number of columns CTTableColumn column = columns.addNewTableColumn(); column.setName("Column" + i); column.setId(i+1);
/** * @deprecated Use {@link #getColumnCount()} instead. * * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) */ @Deprecated @Removal(version = "4.2.0") public long getNumberOfMappedColumns() { return ctTable.getTableColumns().getCount(); }
CTTableColumns ctTableColumns = getCTTable().getTableColumns(); if(ctTableColumns != null) { for (CTTableColumn col : ctTableColumns.getTableColumnList()) { XSSFCell cell = row.getCell(cellnum); if (cell != null) {
private void wrapColumns(Table table) { CTTable ctTable = table.getCTTable(); for (CTTableColumn column : ctTable.getTableColumns().getTableColumnArray()) { column.setName(WrappingUtil.wrapTableColumnName(column.getName())); } }
/** * Remove a column from the table. * * @param column * the column to remove * @since 4.0.0 */ public void removeColumn(XSSFTableColumn column) { int columnIndex = getColumns().indexOf(column); if (columnIndex >= 0) { ctTable.getTableColumns().removeTableColumn(columnIndex); updateReferences(); updateHeaders(); } }
/** * this method update column header of sheet into table * * @param ctTable * xssf table object * @param title * title of column * @param index * index of column */ private void updateSheetTable(CTTable ctTable, String title, int index) { CTTableColumns tableColumnList = ctTable.getTableColumns(); CTTableColumn column = null; for( int i = 0; tableColumnList.getCount() < index; i++) { column = tableColumnList.addNewTableColumn(); column.setId(i); } column = tableColumnList.getTableColumnArray(index); column.setName(title); }
/** * Remove a column from the table. * * @param columnIndex * the 0-based position of the column in the table * @throws IllegalArgumentException * if no column at the index exists or if the table has only a * single column * @since 4.0.0 */ public void removeColumn(int columnIndex) { if (columnIndex < 0 || columnIndex > getColumnCount() - 1) { throw new IllegalArgumentException("Column index out of bounds"); } if(getColumnCount() == 1) { throw new IllegalArgumentException("Table must have at least one column"); } CTTableColumns tableColumns = ctTable.getTableColumns(); tableColumns.removeTableColumn(columnIndex); tableColumns.setCount(tableColumns.getTableColumnList().size()); updateReferences(); updateHeaders(); }
columns.setCount(3); CTTableColumn column = columns.addNewTableColumn(); column.setId(++i); column.setName(colName);
CTTableColumn column = columns.insertNewTableColumn(columnIndex); columns.setCount(columns.sizeOfTableColumnArray());
/** * @return the number of mapped table columns (see Open Office XML Part 4: chapter 3.5.1.4) */ public long getNumerOfMappedColumns(){ return ctTable.getTableColumns().getCount(); }
/** * Note this list is static - once read, it does not notice later changes to the underlying column structures * To clear the cache, call {@link #updateHeaders} * @return List of XSSFTableColumn * @since 4.0.0 */ public List<XSSFTableColumn> getColumns() { if (tableColumns == null) { List<XSSFTableColumn> columns = new ArrayList<>(); CTTableColumns ctTableColumns = ctTable.getTableColumns(); if (ctTableColumns != null) { for (CTTableColumn column : ctTableColumns.getTableColumnList()) { XSSFTableColumn tableColumn = new XSSFTableColumn(this, column); columns.add(tableColumn); } } tableColumns = Collections.unmodifiableList(columns); } return tableColumns; }