JExcel 警告:无法在 A257 添加单元格,因为它超出了最大列限制'
我被要求将我的网络应用程序中的平均数据量(基本上是来自 SQL 的列表)添加到可下载的 Excel 文件中,因此我创建了一个 servlet 来生成 Excel。
问题是jxl API似乎不喜欢超过256行,而我的数据是一千多。
有什么办法可以绕过这个限制吗? 如果可以的话我想继续使用这个API(不需要在服务器中安装不同的API,而且很容易使用)。但如果必须的话我会改变。
感谢大家!
PS: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;
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;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应该是
等等。您面临的不是行限制,而是列限制。查看这些 javadocs。
should be
and so on. It is not the row limit you are facing, but column limit. Check out these javadocs.
我认为直到最新版本的 Excel 才支持超过 256 列。我认为您的库还没有跟上最新版本。
如果您只需要基本的 XLS 生成功能,您实际上可以将 HTML 表格另存为具有关联 mime 类型的 .XLS,Excel 将透明地打开它。我怀疑你可以用这种方法做任何像公式、图表或其他聪明的事情。
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.