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

前端 未结 11 2089
余生分开走
余生分开走 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-07 22:58

    If you are processing in rows with cellIterator....then this worked for me ....

      DataFormatter formatter = new DataFormatter();   
      while(cellIterator.hasNext())
      {                         
            cell = cellIterator.next();
            String val = "";            
            switch(cell.getCellType()) 
            {
                case Cell.CELL_TYPE_NUMERIC:
                    val = String.valueOf(formatter.formatCellValue(cell));
                    break;
                case Cell.CELL_TYPE_STRING:
                    val = formatter.formatCellValue(cell);
                    break;
            }
        .....
        .....
      }
    

提交回复
热议问题