0

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

enter image description here

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 - 
Community
  • 1
  • 1
user1798578
  • 221
  • 3
  • 12
  • 1
    Are you 100% sure that the cell only contains alfanumeric value. I've had similar problems with POI... when it turned out that the string in fact had an apostrophe at the end. This dont show when looking at the cell... but it shows when clicking it and looking at the excel "formula bar". – su99-bsa Jun 30 '16 at 11:27
  • logout the exception, so you know what is happend – Jens Jun 30 '16 at 11:29
  • yes the cell only contains alphanumerical values both in the cell and the formula bar... if you have a look at cell 2,E - (2113 1) java/poi prints this value...but when it tries to print cell 2,M (12345678) nothing gets printed out – user1798578 Jun 30 '16 at 11:35
  • no exception is thrown? – user1798578 Jun 30 '16 at 11:36

0 Answers0