aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Populate Excel Spreadsheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Populate Excel Spreadsheet" Watch "Populate Excel Spreadsheet" New topic
Author

Populate Excel Spreadsheet

Sam Gehouse
Ranch Hand

Joined: Jul 21, 2003
Posts: 281
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

Joined: Oct 29, 2001
Posts: 8900
    
    8

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.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41816
    
  62
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.


Ping & DNS - my free Android networking tools app
Dhanya Palanisamy
Ranch Hand

Joined: Oct 20, 2006
Posts: 61
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populate Excel Spreadsheet