6

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.

Jonik
  • 80,077
  • 70
  • 264
  • 372
user93796
  • 18,749
  • 31
  • 94
  • 150

7 Answers7

8

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

Community
  • 1
  • 1
Jonik
  • 80,077
  • 70
  • 264
  • 372
  • 1
    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 May 21 '10 at 12:17
  • I have tried this, the output excel file's format is HTML and it can't open in Excel viewer. I am looking for a solution to export excel format file from JSP.Any suggestion? – Geln Yang Feb 17 '11 at 07:56
  • @Geln, did you try using CSV or JasperReports as suggested by @BalusC above? – Jonik Feb 17 '11 at 14:37
  • CSV or JasperReports has its own machanism to create excel and need to recreate the report in new format (now is JSP) . But I don't want do this. Now I need a solution that converting HTML format excel to MS Excel. – Geln Yang Feb 18 '11 at 08:45
4

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.

Robert Campbell
  • 6,848
  • 12
  • 63
  • 93
2

It's different in each case.

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

cletus
  • 616,129
  • 168
  • 910
  • 942
1

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

user18943
  • 759
  • 1
  • 9
  • 18
1

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.
  • 23,300
  • 18
  • 98
  • 136
0

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.

Paul Jowett
  • 6,513
  • 2
  • 24
  • 19
0

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

Fortyrunner
  • 12,702
  • 4
  • 31
  • 54