Alternative to deprecated getCellType

后端 未结 8 2300
自闭症患者
自闭症患者 2020-11-27 05:44

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

This is my code:

try (FileInputStream fileInputStream = new FileInputStr         


        
8条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-27 06:06

    You can do this:

    private String cellToString(HSSFCell cell) {
        CellType type;
        Object result;
        type = cell.getCellType();
    
        switch (type) {
            case NUMERIC :  //numeric value in excel
                result = cell.getNumericCellValue();
                break;
            case STRING : //String Value in Excel
                result = cell.getStringCellValue();
                break;
            default :
                throw new RuntimeException("There is no support for this type of value in Apche POI");
        }
        return result.toString();
    }
    

提交回复
热议问题