已弃用的 getCellType 的替代方法 [英] Alternative to deprecated getCellType
本文介绍了已弃用的 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屋!
查看全文