views:

81

answers:

2

Hello!

I was asked to add an average amount of data from my web-app (basically a List from a SQL) into a downloadable Excel file, so I did a servlet to generate the Excel.

Problem is that jxl API doesn’t seem to like more than 256 rows, and my data is more than a thousand.

Is there any way to go around this limitation? I would like to keep using this API if I could (no need to install different APIs in the server and it’s easy to use). But I will change if I must.

Thanks for all!

PS: here is the main code of the servlet:

List<TableProject> sql = (List<TableProject>)session.getAttribute("sql");
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=Export.xls");
w = Workbook.createWorkbook(response.getOutputStream());
s = w.createSheet("Consult Project", 0);
for(int i=0;i<sql.size();i++){

 s.addCell(new Label(i,0,sql.get(i).getCod_project()));
 s.addCell(new Label(i,1,sql.get(i).getTxt_project()));
 s.addCell(new Label(i,2,sql.get(i).getDate_notification()));
 s.addCell(new Label(i,3,sql.get(i).getDate_last_action()));
 s.addCell(new Label(i,4,sql.get(i).getTxt_personal()));
 s.addCell(new Label(i,5,sql.get(i).getTxt_estate()));
 s.addCell(new Label(i,6,sql.get(i).getTxt_provider()));

}
w.close();
w = null;
+1  A: 

I think until recent versions of Excel it doesn't support more than 256 columns. I assume that your library hasn't caught up with the latest release.

If you only need basic XLS generation features, you can actually save a HTML table as a .XLS with associated mime-type, and Excel will open it transparently. I doubt you can do anything like formulae or charts or anything else clever with that approach though.

Rich
I searched through the net and making a direct export of a html table to Excel seems not to be a good practice. But If it ends to that it's another tool I can use. Thanks!
Random
+2  A: 
s.addCell(new Label(i,0,sql.get(i).getCod_project()));

should be

s.addCell(new Label(0, i,sql.get(i).getCod_project()));

and so on. It is not the row limit you are facing, but column limit. Check out these javadocs.

Georgy Bolyuba
+1 for noticing that the OP mentioned rows not columns :)
Rich
Thanks! I should have read the documentation better...
Random