• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Populate Excel Spreadsheet

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic