48043
2009-10-23 07:07:04 +0000
Excel complains about a POI generated function
2015-10-29 09:01:47 +0000
1
1
1
Unclassified
POI
HSSF
3.7-FINAL
PC
Windows XP
NEEDINFO
P1
normal
---
1
alamothe
dev
alamothe
ivano.diana
onealj
0
oldest_to_newest
131326
0
alamothe
2009-10-23 07:07:04 +0000
When I insert the following function in a cell:
=IF(AND(ISBLANK(A10),ISBLANK(B10)),"",CONCATENATE(A10,"-",B10))
using:
cell.setCellFormula(
"IF(AND(ISBLANK(A10)," +
"ISBLANK(B10)),\"\"," +
"CONCATENATE(A10,\"-\",B10))");
Excel complains about it (#VALUE!) when the workbook is first opened. However, it is enough just to press F2, Enter on a cell for the function to start evaluating properly. Interestingly, this problem does not appear in OpenOffice.
131729
1
suatgonul
2009-11-05 08:09:59 +0000
I have the same problem and the code causing this problem looks like the following one:
String formula = "IF(F2<>\"\",CONCATENATE(F2,\" \",G2),G2)";
cell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
cell.setCellFormula(formula);
In detail, when both F2 and G2 cells are filled with some text, the problem occurs but when F2 contains empty string, the problem does not occur.
I add a text into F2 cell with a code like in the following:
String str = "foo";
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
cell.setCellValue(str);
PS: all cell variables have the type of HSSFCell.
PS2: I open the file I created; enter some text into F2 manually; press enter; and the formula cell again has #VALUE!. After clicking the formula cell, it shows the correct value.
145567
2
ivano.diana
2011-04-05 12:17:32 +0000
I encountered some problems with HSSF component when using "CONCATENATE" function inside an excel formula. In particular, it seems this function doesn't work when inside other function or instructions-for example inside an IF. I post some code examples to better explain the problem:
cellFormula.setFormula("IF(true, CONCATENATE(B2,B3), \"\")");
cellFormula.setFormula("CONCATENATE(IF(C2=\"X\",CONCATENATE(B2,\" \"),\"\"),IF(C3=\"X\",CONCATENATE(B3,\" \"),\"\"),IF(C4=\"X\",CONCATENATE(B4,\" \"),\"\"))");
The issue is the classic "#VALUE!" that appears when trying to evaluate the formula.
I was wondering if as happened with "Bug 50384" you are providing to fix it in Dev versions.
145647
3
apache
2011-04-08 11:12:34 +0000
(In reply to comment #2)
> cellFormula.setFormula("IF(true, CONCATENATE(B2,B3), \"\")");
To confirm, if you set this formula and then run the formula evaluator, it'll show as #VALUE! in excel? And if so, what does POI evaluate the cell too, is that the correct string or not?
145684
4
ivano.diana
2011-04-11 03:06:23 +0000
(In reply to comment #3)
> (In reply to comment #2)
> > cellFormula.setFormula("IF(true, CONCATENATE(B2,B3), \"\")");
>
> To confirm, if you set this formula and then run the formula evaluator, it'll
> show as #VALUE! in excel? And if so, what does POI evaluate the cell too, is
> that the correct string or not?
Of course, even if I run the formula evaluator what i obtain in excel is "#VALUE!". However if i try to read the cell with POI what i retrieve is the expected value.
if we're going wrong, any suggestion is welcome.
185681
5
onealj
2015-10-07 09:55:35 +0000
Make sure you're using some evaluation that will cache the formula result in the cell, such as FormulaEvaluator.evaluateInCell(Cell). FormulaEvaluator.evaluate(Cell) returns the formula result but leaves the Cell unmodified. Perhaps this is why you were still getting #VALUE! errors when you opened the workbook in Excel.
Could you post the code you used to evaluate the formula after setting the formula but before saving the workbook?
Alternatively, you might be able to try Workbook. setForceFormulaRecalculation(true) before saving the workbook, which tells Excel to recalculate all the formulas next time it opens the workbook.