How to get numeric and string value from excel file cell, using POI , i am getting error for numeric value, string value easily fetch [duplicate]

不问归期 提交于 2019-12-25 06:49:53

问题


Currently i am using String data= sheet1.getRow(row).getCell(column).getStringCellValue(); It works properly for String value but displays error for numeric value. So i have to add numeric value like "34567" in excel. Is there any other method to fetch both numeric and String ?


回答1:


You will get an error when you try to fetch the numeric cell as String.

You should be setting the cellType as string like below, before fetching the numeric cell.

   HSSFCell yourCell = sheet1.getRow(row).getCell(column);
   yourCell.setCellType(Cell.CELL_TYPE_STRING);
   String data = yourCell.getStringCellValue();



回答2:


in the template excel change the column type as string.then get the value as string as follows sheet1.getRow(row).getCell(column).getStringCellValue().Then pasrse to integer or whatever.



来源:https://stackoverflow.com/questions/37654456/how-to-get-numeric-and-string-value-from-excel-file-cell-using-poi-i-am-getti

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!