https://bz.apache.org/bugzilla/show_bug.cgi?id=66215

--- Comment #2 from Axel Richter <[email protected]> ---
Formula shifter seems to work on Ptg-level. Me not able fully understand this
though. All I can contribute is a work around. See new code in
https://stackoverflow.com/questions/52877212/expanding-an-existing-table-in-excel-using-apache-poi/52904452#52904452.

...
   if (totalsRowCount > 0) {
    //if we have totals rows, shift totals rows down
    sheet.shiftRows(lastTableDataRow, lastTableRow, 1);
    //correct all sheet table-reference-formulas which probably got damaged
after shift rows
    for (CTTableColumn tableCol :
table.getCTTable().getTableColumns().getTableColumnList()) {
     if (tableCol.getCalculatedColumnFormula() != null) {
      int id = (int)tableCol.getId();
      String formula = tableCol.getCalculatedColumnFormula().getStringValue();
      int rFirst = table.getStartCellReference().getRow() +
table.getHeaderRowCount();
      int rLast = table.getEndCellReference().getRow() -
table.getTotalsRowCount();
      int c = table.getStartCellReference().getCol() + id - 1;
      sheet.getWorkbook().setCellFormulaValidation(false);
      for (int r = rFirst; r <= rLast; r++) {
       XSSFRow row = sheet.getRow(r); if (row == null) row =
sheet.createRow(r);
       XSSFCell cell = row.getCell(c); if (cell == null) cell =
row.createCell(c);
       cell.setCellFormula(formula);
      }
     }
    }
   }
...

Maybe this can be implemented after shiftRows shiftted rows of a XSSFTable, if
that can be detected somehow.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to