I want to export multiple data tables, each in a separate sheet, in one Excel file using primefaces 4.0 or primefaces extension exporter. Can this be done?
Asked
Active
Viewed 1,206 times
0
-
1get all the data and use Apache poi to create all sheets in one file, what do you think ? – Jalal Sordo Feb 28 '14 at 21:34
1 Answers
1
Use the jxl framework for Excel file handling. I think it is still one of the best options.
An example:
public void createExcelReport(OutputStream stream) {
WritableWorkbook workbook = null;
try {
Workbook template = Workbook.getWorkbook(new File(getClass().getResource("/report/report_template.xls").getFile()));
workbook = Workbook.createWorkbook(stream, template);
WritableSheet sheet = workbook.getSheet(0);
int idx = START_ROW_IDX;
for (SomePojo pojo : pojoService.getPojos()) {
writePojoToRow(pojo);
idx++;
}
if (idx == START_ROW_IDX) {
addNoErrorSheet(sheet);
}
workbook.write();
} catch (Exception e) {
log.error("There was a problem here.", e);
throw new RuntimeException("Excel file creation did not work because of this Exception: ", e);
} finally {
if (workbook != null) {
try {
workbook.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}

Adam Arold
- 29,285
- 22
- 112
- 207
-
I would like to use primefaces or apache-poi only if possible since this page is a part of a bigger project. Thanks for the suggestion though. – Ni12N Feb 28 '14 at 13:41