Good day people. I am working on a java-ee project, specifically working on exporting a datable to spreadhseet(xls). I have a method called postProcessXLS. I use this method to auto adjust the column width of the generated spreadsheet and also to add cell styles and formatting. When i run the app, the method postProcessXLS throws a null pointer exception without referencing the line.
bean
public void postProcessXLS(Object document) throws IOException, BadElementException, DocumentException {
try {
HSSFWorkbook wb = (HSSFWorkbook)document;
HSSFSheet sheet = wb.getSheetAt(0);
HSSFRow header = sheet.getRow(0);
HSSFCellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(HSSFColor.GREEN.index);
cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
for (int i = 0; i < header.getPhysicalNumberOfCells(); i++) {
HSSFCell cell = header.getCell(i);
cell.setCellStyle(cellStyle);
}
for (int colNum = 0; colNum < header.getLastCellNum(); colNum++) {
sheet.autoSizeColumn(colNum);
}
} catch (Exception ex) {
LOG.error("Could not process spreadsheet" + ex);
}
}