0

NullPointerException raise while trying update a excel cell using Apache POI. Particular cell that I want to update has some value but I can't update due to exception.

String excelFileName = "D:\\TempLocation\\Marks.xlsx";//name of excel file
String sheetName = "Sheet1";//name of sheet
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = wb.getSheet(sheetName) ;
System.out.println(regNo+ " " + cellNo);
Cell cellToUpdate = sheet.getRow(0).getCell(0);
cellToUpdate.setCellValue(mark);
FileOutputStream fileOut = new FileOutputStream(excelFileName);
//write this workbook to an Outputstream.
wb.write(fileOut);
fileOut.flush();
fileOut.close();

this is my code. Exception raised at this line:

Cell cellToUpdate = sheet.getRow(0).getCell(0);
Udhaya
  • 121
  • 1
  • 14

1 Answers1

0

Inclusion of this line

FileInputStream  fis = new FileInputStream(new File(excelFileName));

And changes in this line

XSSFWorkbook wb = new XSSFWorkbook(fis);

Makes it to work.

Udhaya
  • 121
  • 1
  • 14