I'm trying to export tableView
to excel using Apache POI
Every thing is well but I need export all my table not just items, I mean with columns names when I use this code:
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet spreadsheet = workbook.createSheet("sample");
HSSFRow row = null;
for (int i = 0; i < TousEmpSusp.getItems().size(); i++) {
row = spreadsheet.createRow(i);
for (int j = 0; j < TousEmpSusp.getColumns().size(); j++) {
row.createCell(j).setCellValue(TousEmpSusp.getColumns().get(j).getCellData(i).toString());
}
}
it exports only items, I tried to modify it like this:
for (int j = 0; j < TousEmpView.getColumns().size(); j++) {
row.createCell(j).setCellValue(TousEmpView.getColumns().get(j).getText());
}
for (int i = 0; i < TousEmpView.getItems().size(); i++) {
row = spreadsheet.createRow(i+1);
for (int j = 0; j < TousEmpView.getColumns().size(); j++) {
row.createCell(j).setCellValue(TousEmpView.getColumns().get(j).getCellData(i).toString());
}
}
but it invokes IndexOutOfBoundsException
.
So how can I export tableView
with column names? What should I modify?
row.createCell(j).setCellValue(TousEmpView.getColumns().get(j).getText());
can get column name but i have a trick to add this line to my code. – Menai Ala Eddine - Aladdin Sep 02 '17 at 22:46