已弃用的getCellType的替代方法 [英] Alternative to deprecated getCellType

查看:14065
本文介绍了已弃用的getCellType的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用org.apache.poi 3.15读取excel文件(文件扩展名为xlsx)。

I'm reading an excel-file (file extension xlsx) using org.apache.poi 3.15.

这是我的代码:

try (FileInputStream fileInputStream = new FileInputStream(file); XSSFWorkbook workbook = new XSSFWorkbook(file)) {
    XSSFSheet sheet = workbook.getSheetAt(0);
    Iterator<Row> rowIterator = sheet.iterator();
    while (rowIterator.hasNext()) {
        Row row = rowIterator.next();

        Iterator<Cell> cellIterator = row.cellIterator();
        while (cellIterator.hasNext()) {
            Cell cell = cellIterator.next();
            switch (cell.getCellType()) {
                case Cell.CELL_TYPE_NUMERIC:
                    System.out.print(cell.getNumericCellValue() + "(Integer)\t");
                    break;
                case Cell.CELL_TYPE_STRING:
                    System.out.print(cell.getStringCellValue() + "(String)\t");
                    break;
            }
        }
        System.out.println("");
    }
} catch (Exception e) {
    e.printStackTrace();
}

我收到一条警告 cell.getCellType() 已弃用。任何人都可以告诉我替代方案吗?

I get a warning that cell.getCellType() is deprecated. Can anyone tell me the alternative?

推荐答案

接受的答案显示了弃用的原因但未命名替代方案:

The accepted answer shows the reason for the deprecation but misses to name the alternative:

CellType    getCellTypeEnum()

其中 CellType 是描述单元格类型的枚举。

where the CellType is the enum decribing the type of the cell.

计划是在POI 4.0中重命名 getCellTypeEnum()返回 getCellType()

The plan is to rename getCellTypeEnum() back to getCellType() in POI 4.0.

这篇关于已弃用的getCellType的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆