The mods are a little gun hoe on this website and locked this tread before i could answer with a solution.
The solution to my problem was explained in this threa by user Vijay How to get numeric and string value from excel file cell, using POI , i am getting error for numeric value, string value easily fetch
i needed to specify that i wanted to reasd the cell as a string and not as an numeric field. Thnis was achieved by adding the following code... Cell.setCellType(Cell.CELL_TYPE_STRING);
Solution
public static String getCellData(int RowNum, int ColNum) throws Exception {
try {
Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
Cell.setCellType(Cell.CELL_TYPE_STRING);
String CellData = Cell.getStringCellValue();
return CellData;
} catch (Exception e) {
return "";
}
}
I'm trying to get the numerical string from an Excel file (image below) but for some reason POI
or Java
won't read the cell value in row 3 column E or row 2 column M but it has no problem retrieving the cell value from row 2 cell E.
Does anyone know why this is happening? I'm struggling to find an answer to this.
After more testing the same issue is also present with HSSF!?!
Here's my java code
getPostalCode = ExcelUtilsXSSF.getCellData(x, System_Constants.PostalCode);
System.out.println("the postal code is "+getPostalCode);
And the java/poi code
public static String getCellData(int RowNum, int ColNum) throws Exception {
try {
Cell = ExcelWSheet.getRow(RowNum).getCell(ColNum);
String CellData = Cell.getStringCellValue();
return CellData;
} catch (Exception e) {
return "";
}
}
Image of the Excel file
Output to the console
the country is - Country
the state is - state
the city is - City
the address is - address
the postal code is -
the employee is 1000-20000
the industry is IT
the company name is 3M Australia
the linkein company name is
the firstname is - Joe
the lastname is - Bloggs
the jobtitle is - Finance & IT Manager
the phone number is -