I am using the following code to read zip code from my excel file which has value like this:
06785
The excel file cell is formatted as special >> zipcode
File src = new File("C:\\Users\myxl.xlsx");
FileInputStream fis = new FileInputStream(src);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sh1 = wb.getSheetAt(0);
System.out.println(sh1.getRow(1).getCell(19).getRichStringCellValue());
//Output = Can not get a text value form a numeric cell
wb.close();
fis.close();
I have tried the followings:
System.out.println(sh1.getRow(1).getCell(19).getStringCellValue());
//Output = Can not get a text value form a numeric cell
System.out.println(sh1.getRow(1).getCell(19).toString());
//Output = 6785.0
System.out.println(sh1.getRow(1).getCell(19).getNumericCellValue());
//Output = 6785.0
System.out.println(sh1.getRow(1).getCell(19).getRawValue());
//Output = 6785
I can not get the value exactly as it appears within excel, which is 06785, it always prints without the 0 or with .0
Would anyone be able to help with this as how I would get an output of the zip code as it exactly appears in excel - 06785?