我正在使用 Apache POI 3.17。
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
我尝试仅处理字符串单元 - 但它不起作用。
不确定这是一个错误还是我使用错误。
...
Cell c = row.getCell (col);
if (c != null)
{
CellType ct = c.getCellTypeEnum ();
System.out.println (ct + " vs " + CellType.STRING);
if (ct == CellType.STRING);
{
System.out.println (" equal");
}
}
...
输出:
STRING vs STRING
equal
BLANK vs STRING
equal
STRING vs STRING
equal
FORMULA vs STRING
equal
为什么任何事物都是“平等”的?
即使我将 == 更改为 equals 或compareTo 也是一样的。
最佳答案
CellType
按预期工作,但此行末尾有令人讨厌的分号(拼写错误):
if (ct == CellType.STRING);
因此,无论条件如何评估,该 block 始终都会执行。
关于java - Apache POI : CellType compare does not work as expected,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52364615/