views:

2254

answers:

8

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  A: 

It's different in each case.

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

cletus
+3  A: 

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.

rcampbell
is jasperreport free
is jasperreprt?
Yes, it is free
rcampbell
A: 

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

Fortyrunner
A: 

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.

jb
+6  A: 

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

Jonik
Note that this isn't directly accepted anymore by the latest Excel versions. Rather use CSV (or JasperReports if you want to have PDF as well).
BalusC
A: 

application/vnd.ms-excel

vivek
Answering "application/vnd.ms-excel", with no explanation at all, is not really helpful in this question. (And, in any case, that idea has already been suggested: http://stackoverflow.com/questions/845439/exporting-jsp-tables-to-excel-word-pdf/846132#846132 - assuming that is what this terse answer meant.)
Jonik
A: 

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.

jowierun
+1  A: 

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

nabeelalimemon