garywald
garywald

Reputation: 21

Print result XSSFCell.setCellFormula()

when I run the folowwing code, he just print the first Formula but not the second, I don't know why.

for(int r = 13;r<15;r++){
        row = sheet.getRow(r);
        cell = row.createCell(i, XSSFCell.CELL_TYPE_FORMULA);
        cell.setCellStyle(StyleOfThisCell.getTotalStyle(workbook));
        String formule = "SUM(C"+(row.getRowNum()+1)+":"+CellReference.convertNumToColString(row.getCell(i-1).getColumnIndex())+(row.getRowNum()+1)+")";
        cell.setCellFormula(formule);
    }

Could you please help me and let me know if I forget something to have my result.

Thanks

I just have seen a problem : I open my excel with libreOffice. If I open it with microsoft excel, I can't see both of my totals. But if I click on activate modification, both of my totals appears. I don't understand.

Upvotes: 1

Views: 987

Answers (1)

garywald
garywald

Reputation: 21

The answer is simple !

After have put a cell with a formule, we need to code an evaluator :

FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
evaluator.evaluateAll();

Thanks Gagravarr !!

Upvotes: 1

Related Questions