I found nullPointerException during writing data in Excel using same code as java selenium…
i.e java.lang.NullPointerException: Cannot invoke method createCell() on null object
I found some solution like during writing data in excel we need to put data in that cell in which we creating cell then only it overwrite and write data in other cell in that row only.
This code is suitable to write data into xlsx file.
_ String excelFileName = “C:\\results.xls”;_
_ File src = new File(excelFileName);_
_ FileInputStream fis = new FileInputStream(src);_
_ HSSFWorkbook wb = new HSSFWorkbook(fis);_
_ HSSFSheet sheet = wb.getSheetAt(0);_
_ HSSFRow row = sheet.createRow(recordcount-1);_
_ WebUI.delay(2)_
_ HSSFCell cell = row.createCell(0);_
_ cell.setCellValue(file.getName());_
_ cell = row.createCell(1);_
_ cell.setCellValue(status);_
_ cell = row.createCell(2);_
_ cell.setCellValue(page);_
_ WebUI.delay(2)_
_ FileOutputStream fileOut = new FileOutputStream(excelFileName);_
_ wb.write(fileOut);_
_ fileOut.flush();_
_ fileOut.close();_
we just write the plain code in the script of our test case or do we need to create a keyword, i have tried many keywords out there but all of them clean my whole spreadsheet and just write the new text katalon send.