So I want to color rows when exporting to Excel but I'm getting a NullPointerException.
This is my code:
HSSFCellStyle cellStyle = hssfWorkbook.createCellStyle();
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
cellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex())
for (int i = 3; i < hssfSheet.getLastRowNum(); i++) {
for (int j = 0; j < hssfSheet.getRow(i).getPhysicalNumberOfCells(); j++) {
hssfSheet.getRow(i).getCell(j).setCellStyle(cellStyle);
}
}
So I noticed when I put a really small numbers of rows (like 3 or 4) it works fine, as soon as I put more, it giving me the exception. I have at least 200 rows, it depends on a filter that the user selects. How to fix this?