Java 将jsp表导出为ex​​cel、word、pdf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/845439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 20:07:01  来源:igfitidea点击:

Exporting jsp tables to excel, word, pdf

javajsppdfms-wordexport-to-excel

提问by user93796

Can anyone suggest me any library/jar files which I can use to export my table to excel/pdf/word.

任何人都可以向我建议我可以用来将我的表格导出到 excel/pdf/word 的任何库/jar 文件。

Please tell me if there is any library by which I can create reports in jsp.

请告诉我是否有任何可以在jsp中创建报告的库。

采纳答案by Jonik

It should also be mentioned that you can export tables to Excel simply by outputting an HTML table, and setting response-type to application/vnd.ms-excel. No external libraries whatsoever needed.

还应该提到的是,您只需输出一个 HTML 表格,并将 response-type 设置为application/vnd.ms-excel. 不需要任何外部库。

Something like this:

像这样的东西:

<%@ page language="java" session="true" %>
<%@ taglib uri="/WEB-INF/tld/response.tld" prefix="res" %>
<res:setHeader name="Content-Type">application/vnd.ms-excel</res:setHeader>
<res:setHeader name="Content-Disposition">attachment; filename=excel-test.xls</res:setHeader>

<table>
    <tr>
        <td>foo</td>
        <td>bar</td>
    </tr>
</table>

Note: this answer is meant to supplement thisand thisas it covers only one of the cases (Excel).

注意:这个答案是为了补充这个这个,因为它只涵盖其中一种情况(Excel)。

回答by cletus

It's different in each case.

每种情况都不同。

As for creating reports, I would instead use a dedicated reporting tool, specifically Jasper Reports.

至于创建报告,我会使用专用的报告工具,特别是 Jasper Reports。

回答by Robert Campbell

I'd say JasperReports- which is open source- is your best bet. It would allow you to code the report once, but export it to the various formats you need. It even supports direct streaming of HTML to the browser, so it really is a code-once, use anywhere type thing. It can also scale up nicely via JasperServer.

我想说JasperReports——它是开源的——是你最好的选择。它允许您对报告进行一次编码,但将其导出为您需要的各种格式。它甚至支持将 HTML 直接流式传输到浏览器,因此它确实是一次代码,可在任何地方使用类型的东西。它还可以通过 JasperServer 很好地扩展。

回答by Fortyrunner

If your spreadsheet is very simple then exporting as CSV is acceptable; its quick and easy to code.

如果您的电子表格非常简单,那么导出为 CSV 是可以接受的;它快速且易于编码。

回答by jb.

I think that itext is still better for report creation, it is more straightforward, i had some (less than enough) experience with Jasper Reports, and it seemed clumsy. OTOH itext is veryeasy to use for developer, and we had pretty big reports done with it, without problems.

我认为 itext 仍然更适合创建报告,它更直接,我对 Jasper Reports 有一些(不够)经验,而且看起来很笨拙。OTOH itext对开发人员来说非常容易使用,我们用它完成了相当大的报告,没有问题。

You may even create rtf's (readable by Word) from itext.

您甚至可以从 itext 创建 rtf(可由 Word 读取)。

回答by Paul Jowett

Docmosisand JODReportscan produce PDF and DOC from the server side (JSPs, servlets, J2EE etc). Docmosis provides formatting/layout in a template so you have less coding to do and possibly even have non-developers maintaining the report look and feel. Both are free.

DocmosisJODReports可以从服务器端(JSP、servlet、J2EE 等)生成 PDF 和 DOC。Docmosis 在模板中提供格式/布局,因此您需要做的编码更少,甚至可能让非开发人员维护报告的外观和感觉。两者都是免费的。

回答by user18943

If you'r working with JSP's you can try using displaytag library which gives you export to all (pdf, excel, csv, xml). You can also customize them or override exporters if you want.

如果您正在使用 JSP,您可以尝试使用 displaytag 库,它可以让您导出到所有文件(pdf、excel、csv、xml)。如果需要,您还可以自定义它们或覆盖导出器。

Just take a look at this url http://displaytag.sourceforge.net/10/export.html

看看这个网址http://displaytag.sourceforge.net/10/export.html