Question

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.

Was it helpful?

Solution

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).

OTHER TIPS

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.

It's different in each case.

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

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.

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

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top