/** * 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); }
for(CTTableColumn col : ctTable.getTableColumns().getTableColumnArray()){ String elementName = SST.toXMLEment(originalTable.getTableColumns().getTableColumnArray(i++).getName());
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>"); }
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++; } } }
@Override public void process(XLXContext context) throws Exception { String style = context.getReportContext().getTableStyleName(); if(style != null){ table.getCTTable().getTableStyleInfo().setName(style); } for(CTTableColumn c : table.getCTTable().getTableColumns().getTableColumnArray()){ Object name = CellExpressionParser.parseExpression(c.getName()).evaluate(context); if(name != null){ c.setName(name.toString()); } } if(header != null){ context.setTableStartHeader(); header.process(context); context.endTableHeader(); generateXMLMap(context); } String tableStartRef = startTable(context); long row = context.getCurrentRow(); forEach.process(context); if(row == context.getCurrentRow()){ context.nextRow();//insert empty row } if(totals != null){ totals.process(context); } processTable(context, tableStartRef); }