aspose file tools*
The moose likes JSP and the fly likes display output table in excel file format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "display output table in excel file format" Watch "display output table in excel file format" New topic
Author

display output table in excel file format

steve francisco
Ranch Hand

Joined: Jan 26, 2005
Posts: 46
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

Joined: Jul 15, 2003
Posts: 618
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

Joined: Dec 04, 2004
Posts: 950
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


Narendra Dhande
SCJP 1.4,SCWCD 1.4, SCBCD 5.0, SCDJWS 5.0, SCEA 5.0
steve francisco
Ranch Hand

Joined: Jan 26, 2005
Posts: 46
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

Joined: Jan 26, 2005
Posts: 46
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

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Frank Sikuluzu
Ranch Hand

Joined: Dec 16, 2003
Posts: 116
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

Joined: Jan 22, 2004
Posts: 185
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

Joined: Dec 11, 2004
Posts: 13410

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: display output table in excel file format