Free Support Forum -

Reading the Excel file


I am using the following code to read the Excel file

Workbook workbook = new Workbook();"D:/sample.xls",FileFormatType.EXCEL2003);
Worksheets worksheet = workbook.getWorksheets();
Workbook wb = new Workbook();
Worksheet sheet = wb.getWorksheets().getSheet(0);

// Access the "A1" cell in the sheet.
Cell cell = sheet.getCells().getCell("A1");
int i = ((Integer)cell.getValue()).intValue();

It is giving me null pointer exception at cell.getValue().Can anybody help?


I think you are making a mistake. According to your code, you create a new workbook from the scratch (wb), get its first worksheet cell i.e., "A1" which will be null if you don't enter any value into it, so when you try to retrieve an integer value from that cell, you got the null pointer error. For confirmation, you may try to utilize and add the following lines of code:



If it's not the case and you are retrieving the cell value from a template (existing) excel file, kindly post your template file with corrected code here, we will check it soon.

Thank you.