Apache POI 和 CellType

问题描述

我对

的版本有点迷茫
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>

我尝试了 3.17、4.0.0 和 5.0.0 版本。

if (c.getCellType () == CellType.NUMERIC.getCode())
{
}

if (c.getCellTypeEnum () == CellType.NUMERIC)
{
}

我无法获得没有弃用或类型错误代码:-(

我正在使用带有 Maven 和 Java 11 的 Eclipe。在版本更改后,我执行了“更新项目”来更新 Maven。

解决方法

apache poi 3.17 Cell.getCellType 中返回 int 但已弃用。 Cell.getCellTypeEnum 返回 CellType。见apache poi 3.17 API: Interface Cell

所以使用 apache poi 3.17 肯定是

if (cell.getCellTypeEnum() == CellType.NUMERIC)

apache poi 大于或等于版本 4.0.0 Cell.getCellType 中返回 CellTypeCell.getCellTypeEnum 也返回 CellType 但已弃用。见apache poi 4.0 API: Interface Cell

所以使用 apache poi 大于或等于版本 4.0.0 它必须

if (cell.getCellType() == CellType.NUMERIC)