Free Support Forum - aspose.com

Reading the Excel file

Hi,

I am using the following code to read the Excel file

Workbook workbook = new Workbook();
workbook.open("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");
System.out.println(cell.toString());
int i = ((Integer)cell.getValue()).intValue();
System.out.println(i);

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

Hi,

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:

System.out.println(cell.getValue());

System.out.println(cell.getStringValue());

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.