• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Populate Excel Spreadsheet

 
Sam Gehouse
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I create a report using JSP. The report gets displayed in a table in the browser. The number of columns of the table (report) is fixed. As such, the table (report) has a fixed number of columns but the number of records could vary. It is a read-only table (report) that gets displayed in the browser in only one table with no requirements for drill-down options.

I want to display the data from the above table (report) in an Excel spreadsheet.

Is POI the only choice? Which jars do I need?

Any help with the sample code would be beneficial.
 
Joe Ess
Bartender
Posts: 9313
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I've done in the past is returned a CSV file from a servlet. Excel is usually set up to open CSV's automatically. If you don't have any fancy formatting that may be an option. Check out this library for easy CVS creation.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If CSV is not an option (e.g., if you need formatting or formulas), then there are a few other libraries besides POI. This page lists a few. POI works well and is easy to use, though.
 
Dhanya Palanisamy
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sam,

For some previous post i have mentioned what i have done in a similar situation. First enclose your displayed table inside a DIV id. On click of some button(save/open Excel) call a javascript function where you can assign the innerHTML from the DIV id to a hidden variable and post. After that in your servlet action just return success. Your deployment descriptor can forward this to another JSP where you can use this code,

<%@ page language="java" contentType="application/vnd.ms-excel"%>
<%response.setHeader("Content-disposition","attachment;filename=Report.xls");%>


Sorry, if you didn't understand, i am bad at expalining. If you are following my steps please feel free to post your questions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic