Cannot get a text value from a numeric cell “Poi”

前端 未结 11 2090
余生分开走
余生分开走 2020-12-07 22:17

I\'m trying to consume data from a spreadsheet in Excel, but always of this error, already tried formatting the worksheet to text and number and still the error persists.

11条回答
  •  长情又很酷
    2020-12-07 23:16

    Formatter will work fine in this case.

    import org.apache.poi.ss.usermodel.DataFormatter;
    
    FileInputStream fis = new FileInputStream(workbookName);
    Workbook workbook = WorkbookFactory.create(fis);
    Sheet sheet = workbook.getSheet(sheetName);
    DataFormatter formatter = new DataFormatter();
    String val = formatter.formatCellValue(sheet.getRow(row).getCell(col));
    list.add(val);   //Adding value to list
    

提交回复
热议问题