Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

display output table in excel file format

 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We need to use jsp/servlet as our tool to retrieve database and display the data table in 1) HTML format and 2) Excel spreadsheet file format.

I want to know how I can display the data table in Excel spreadsheet file format. Is it possible to create an output excel file to allow client download ? How ?

thanks,
steve
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to get the downloaded data to load up in Microsoft Excel on Windows machines is to output it in simple delimited text, like a CSV file. Just copy the following into a text editor, save it as .csv, and Excel will probably open it by default, or if you load it into Excel, it will figure out that it's a comma-separated values file and display each field in its own cell:

12038470, James, Brown, 123 Sesame Street, Miami, Florida
29837473, Frank, Jones, 55 Sunset Blvd, Hollywood, California

So, pull your data out of the database, create a file out of it like the above, and give that to the user, and tell them to open it in Excel (although on Windows .csv files tend to open in Excel by default). From there, they could actually save it as a .xls file if they wanted to.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The CVS format is fine. I want to add little bit more.
To generate a Excel format response, set the response header to "application/vnd.ms-excel" using response.setContentType("application/vnd.ms-excel"); and write all data in Tab deleimited format.

Depend on your Browser setting, the page will open with MS Excel or the browser ask to save the file or open it.

Thank you
 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Narendra Dhande:
Hello,

The CVS format is fine. I want to add little bit more.
To generate a Excel format response, set the response header to "application/vnd.ms-excel" using response.setContentType("application/vnd.ms-excel"); and write all data in Tab deleimited format.

Depend on your Browser setting, the page will open with MS Excel or the browser ask to save the file or open it.

Thank you


Thanks. Could you tell me how to set browser to either open with MS Excel or the browser ask to save the file or open it ? (For IE and Netscape)
 
steve francisco
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Narendra Dhande:
Hello,

The CVS format is fine. I want to add little bit more.
To generate a Excel format response, set the response header to "application/vnd.ms-excel" using response.setContentType("application/vnd.ms-excel"); and write all data in Tab deleimited format.

Depend on your Browser setting, the page will open with MS Excel or the browser ask to save the file or open it.

Thank you


what I prefer to do is --- After user clicks a "Get results" button, he will see a result page showing data in Excel format, and at the bottom of the page, there is small icon saying "download this file", and if he clicks it, he can download it as an Excel file. Is this doable ??

thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would need to use frames.
Frame 1 would have the button that just calls the same URL. If pressed the page is sent down as an attatchment instead of 'inline'.

Frame 2 would have the Excel page as an 'inline' page.
 
Frank Sikuluzu
Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
You would need to use frames.
Frame 1 would have the button that just calls the same URL. If pressed the page is sent down as an attatchment instead of 'inline'.

Frame 2 would have the Excel page as an 'inline' page.


when you say "inline" page, do you mean just let the browser display a web page showing table in Excel cell format ?
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the system delimitor is the same as the delimitor used in CSV file, it
can be opened as an Excel file. Otherwise, it cannot.

A better option is to generate real Excel file instead of CSV file. POI
from jakarta support such functionality.

Dan
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Frank Sikuluzu:


when you say "inline" page, do you mean just let the browser display a web page showing table in Excel cell format ?


Inline will fire up Excel from within your browser, attachment will cause the browser to prompt for download.

Google on Content-Disposition for more information
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic