/** * 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(); }
/** * @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(); }
/** * 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; }
/** * 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(); } }
/** * 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(); }
/** * 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); }
CTTableColumns columns = ctTable.getTableColumns(); if (columns == null) { columns = ctTable.addNewTableColumns();
CTTableColumns ctTableColumns = getCTTable().getTableColumns(); if(ctTableColumns != null) { for (CTTableColumn col : ctTableColumns.getTableColumnList()) {
/** * @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(); }
/** * 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(); }
/** * @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(); }
/** * 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; }
public List<XSSFXmlColumnPr> getXmlColumnPrs() { if(xmlColumnPr==null){ xmlColumnPr = new Vector<XSSFXmlColumnPr>(); for(CTTableColumn column:ctTable.getTableColumns().getTableColumnList()){ if(column.getXmlColumnPr()!=null){ XSSFXmlColumnPr columnPr = new XSSFXmlColumnPr(this,column,column.getXmlColumnPr()); xmlColumnPr.add(columnPr); } } } return xmlColumnPr; }
/** * 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(); } }
private void wrapColumns(Table table) { CTTable ctTable = table.getCTTable(); for (CTTableColumn column : ctTable.getTableColumns().getTableColumnArray()) { column.setName(WrappingUtil.wrapTableColumnName(column.getName())); } }
/** * 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); }
@Override public void process(XLXContext context) throws Exception { CTTableColumns cols = getTable().getCTTable().getTableColumns(); int index = 0; List<Node> cells = getForEach().getChildren().get(0).getChildren(); int offset = getTable().getStartCellReference().getCol(); for(CTTableColumn col : cols.getTableColumnArray()){ String element = SST.toXMLEment( col.getName()); ((XMLCellNode) cells.get(index + offset)).setElement(element); index++; } context.write("<root>\n"); getForEach().process(context); context.write("</root>"); }
CTTableColumns ctColumns = ctTable.getTableColumns(); // setting new table columns will
void buildTableCell(Table table, Node templateNode, XSSFCell cell) { int start = table.getStartCellReference().getCol(); int end = table.getEndCellReference().getCol(); int cellCol = cell.getColumnIndex(); String axis = findAxisCol(cell); CTTableColumn[] ctCols = table.getCTTable().getTableColumns().getTableColumnArray(); int totalsRowCount = (int) table.getCTTable().getTotalsRowCount(); String cellVal = cell.getStringCellValue().trim(); XLSXExpression expr = new SimpleExpression( cellVal); if(totalsRowCount > 0 && cellCol >= start && cellCol <= end ){ CTTableColumn totalCol = ctCols[cellCol - start]; if(totalCol.isSetTotalsRowFunction()){ expr = new AggregateExpression(expr, Function.valueOf((totalCol.getTotalsRowFunction().toString().toUpperCase()))); } } CellNode cellNode = sheetParser.createCellNode(sheet, cell,cell.getColumnIndex(), expr , templateNode ); cellNode.setAxis(axis); templateNode.getChildren().add(cellNode); }
void addTotals(TableNode tableNode, Node templateNode) { Table table = tableNode.getTable(); int totalsRowCount = (int) table.getCTTable().getTotalsRowCount(); if(totalsRowCount > 0){ int endRow = table.getEndCellReference().getRow(); XSSFRow tRow = sheet.getRow(endRow); Node totalsRow = sheetParser.createTotalsNode(sheet, tableNode, tRow ); tableNode.addTotals(totalsRow); int index = table.getStartCellReference().getCol(); insertBlanks(templateNode, tRow, totalsRow, index); for( CTTableColumn ctCol : table.getCTTable().getTableColumns().getTableColumnArray()){ if(ctCol.isSetTotalsRowFunction()){ buildTotalsCell(templateNode, tRow, totalsRow, index); }else { XSSFCell cell = sheet.getRow(endRow).getCell(index, Row.CREATE_NULL_AS_BLANK); totalsRow.getChildren().add(sheetParser.createCellNode(sheet, cell, cell.getColumnIndex(), CellExpressionParser.parse(cell), templateNode)); } index++; } } }