I've written a simple web app with JSF which is used to download Excel reports. I'm able to write to at least 50,000 rows with six columns onto five different sheets in under ten seconds.
The problem comes when I try to format the Excel data. The formatting takes quite sometime and important thing is when I try to format Excel with data more than 3,000 rows and download through the JSF, it throws the Zip Bomb IO exception.
Due to this, I'm unable to compute the size of the formatted workbook also (which requires writing to a byteoutputstream).
Can anybody provide any insight on this?
Is it possible to download from the server a fully formatted Excel which has 50K rows in five sheets?
Below is the code I use for formatting the Excel rows.
For Header row:
public CellStyle formatHeaderRow(SXSSFWorkbook sxWorkBook){
CellStyle cellStyleHeader = sxWorkBook.createCellStyle();
Font font = sxWorkBook.createFont();
font.setFontHeightInPoints((short)10);
font.setFontName("Arial");
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
cellStyleHeader.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
cellStyleHeader.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyleHeader.setBorderTop((short) 1);
cellStyleHeader.setBorderLeft((short) 1);
cellStyleHeader.setBorderRight((short) 1);
cellStyleHeader.setBorderBottom((short) 1);
cellStyleHeader.setAlignment((short) CellStyle.ALIGN_CENTER);
cellStyleHeader.setFont(font);
return cellStyleHeader;
}
For data rows:
public CellStyle formatBodyRows(SXSSFWorkbook sxWorkBook){
CellStyle cellStyleBody = sxWorkBook.createCellStyle();
Font bodyFont = sxWorkBook.createFont();
bodyFont.setFontHeightInPoints((short)10);
bodyFont.setFontName("Arial");
cellStyleBody.setBorderTop((short) 1);
cellStyleBody.setBorderLeft((short) 1);
cellStyleBody.setBorderRight((short) 1);
cellStyleBody.setBorderBottom((short) 1);
cellStyleBody.setAlignment((short) CellStyle.ALIGN_LEFT);
cellStyleBody.setFont(bodyFont);
return cellStyleBody;
}
For column/cell spacing:
for(int cellCount=0;cellCount<row.getLastCellNum();cellCount++){
sheet.setColumnWidth(cellCount, width);
row.getCell(cellCount).setCellStyle(cellStyleHeader);
}