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++; } } }