Exporting jsp tables to excel, word, pdf

Deadly 提交于 2019-12-21 13:12:21

问题


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

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


回答1:


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.

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 this and this as it covers only one of the cases (Excel).




回答2:


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.




回答3:


It's different in each case.

  • Excel: use JExcelAPI or Apache POI;
  • PDF: use iText;
  • Word: Apache POI again.

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




回答4:


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 very easy to use for developer, and we had pretty big reports done with it, without problems.

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




回答5:


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.

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




回答6:


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




回答7:


Docmosis and JODReports can 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.



来源:https://stackoverflow.com/questions/845439/exporting-jsp-tables-to-excel-word-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!