0
votes

I'am using POI in order to read excels files from my users. In one of the cells, i've got this formula :

IF(H24>0,((D24*(Q24))/((3600*H24)/I24))+IF(AND(N24>0,L24>0),(D24*L24*(Q24)/N24),0),0)

The problem arrive when i've got a 0 value for N24. In this case, POI returns me an DIV/0 error, but i don't understand why .. because of the IF (N24>0) test.

Anyway, I tried changing the formula and keep only the latest part like this : IF (N24>0,D24*L24*(Q24)/N24),0) => still doesn't work.

To Evaluate the formula I use : FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); switch (evaluator.evaluateFormulaCell(cell))

.....

I am using POI 3.10, same pb with 3.11

Any idea ?

2
Can you create an even simpler formula that shows the problem? If so, it's probably worth submitting a bug report to Apache POI - Gagravarr
Your second example lacks a opening parenthesis. And with your first example: sure that not I24 = 0? Because this is not tested. - Axel Richter
@AxelRichter, Yes I saw, i forget it when i did the copy/past. Sorry. With the excel i have, I24 is always >0. I only have got the problem with the cell N24 wich is equal to 0. - Jean-Philippe Iwasinta
@Gagravarr => Already add it : with IF (N24>0,D24*L24*(Q24)/N24,0) - Jean-Philippe Iwasinta
@pnuts Just tried to change the formula. Still have error on evaluating the formula. - Jean-Philippe Iwasinta

2 Answers

0
votes

We found a Bypass. When using the method evaluateFormulaCell, it was impossible to get the catchedValue.

By using the valuator.evaluate(cell), we still have the error but we can get the catchedValue.

0
votes

Found the prog error; In order to get an long, the developer coded this :

Thanks for your response and sorry ...

I found an error of programation.

To get a long, the developer used this method :

public static Object getCellValue(Row row, int index) {
    if (row == null || row.getCell(index) == null) {
        return null;
    }
    Object retour = null;
    Cell cell = row.getCell(index);
    cell.setCellType(Cell.CELL_TYPE_STRING);
    String val = cell.getStringCellValue().trim();
    if (val != null && !"".equals(val)) {
        retour = cell.getStringCellValue();
    }

    return retour;
}

The gulty is : cell.setCellType(Cell.CELL_TYPE_STRING); ....