简体   繁体   English

我的公式在poi HSSFCell setCellFormula中出了什么问题?

[英]What's wrong w/my formula in poi HSSFCell setCellFormula?

I'm trying to set a simple formula in a spreadsheet that just subtracts the value of one cell from another. 我试图在电子表格中设置一个简单的公式,只是从另一个单元格中减去一个单元格的值。 This is the relevant code snippet. 这是相关的代码段。

residentialCell.setCellType(HSSFCell.CELL_TYPE_FORMULA);
residentialCell.setCellFormula(formula);

This is the error I get when it runs: 这是我运行时得到的错误:

Exception in thread "main" org.apache.poi.ss.formula.FormulaParseException: Unused input [E] after attempting to parse the formula [2E-8E]
    at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:1573)
    at org.apache.poi.ss.formula.FormulaParser.parse(FormulaParser.java:176)
    at org.apache.poi.hssf.model.HSSFFormulaParser.parse(HSSFFormulaParser.java:72)

The formula should be "2E-8E" like it says. 公式应该是“2E-8E”,就像它说的那样。 This seems simple enough, so sorry if I'm overlooking something that should be obvious to me. 这看起来很简单,如果我忽略了一些对我来说应该是显而易见的事情,那就很抱歉。 I've googled this for quite a while, and all the examples I've found seem to suggest that this should work. 我用谷歌搜索了一段时间,我发现的所有例子似乎都表明这应该有效。 Any suggestions? 有什么建议么?

Thanks! 谢谢!

You have your row/column designation backwards. 您的行/列指定向后。 Assuming that it's part of a larger formula, your probably want "E2-E8" instead of "2E-8E" . 假设它是更大公式的一部分,你可能想要"E2-E8"而不是"2E-8E"

The error indicates that whatever parsed this part recognized "2E-8" as a valid floating-point literal number, with an extra "E" that can't be parsed as anything meaningful. 该错误表明无论解析该部分是什么,都将“2E-8”识别为有效的浮点数字,并且额外的“E”不能被解析为有意义的任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM