Apache POI 3.x - Logical formula resulting in #VAL

2019-09-20 00:51发布

问题:

I've developed a code that creates a XLS file using Apache POI 3.9.
The sheet has two columns that contains only boolean values, as shown below:

The generated XLS file was opened using a MS Excel 2010 in Portuguese (pt-BR), thus consider VERDADEIRO as TRUE and FALSO as FALSE. The 3rd column contains the formula INT(AND(L2,NOT(M2))) varying references L2 and M2 for each row. This formula is a logical expression that has its result converted to integer. However, when the file is opened using MS Excel 2010 the formula results in error (represented by #VALUE!). I've tested the same file using OpenOffice Calc, LibreOffice Calc and MS Excel 2011 for Mac and it worked fine for both of them.
The error disappeared and the correct value was displayed when I pressed F2 and then hit Enter for each cell.

回答1:

I changed the formula adding parenthesis around the function call NOT(M2)
INT(AND(L2,NOT(M2))) ====> INT(AND(L2,(NOT(M2)))) and the problem was solved.