wood burning stoves 2.0*
The moose likes JSP and the fly likes Saving data to Excel files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Saving data to Excel files" Watch "Saving data to Excel files" New topic
Author

Saving data to Excel files

Anant Kadiyala
Greenhorn

Joined: Aug 29, 2001
Posts: 24
Hi,
I have a web page (JSP) that renders some data in HTML tables. We would like to have an �export to Excel button� on the page. What is the best way to export HTML data from JSP into an Excel file?
I know that Excel can read HTML and CSV formats. But the requirement is to save the user the trouble of doing the import in Excel. When the user opens the .xls file, they should have everything readily formatted for them. The formatting itself is not very complex. It is a simple table. So, basic column headers and a title for the report would do.
Any ideas??!!
Thanks,
Anant


IBM Certified in Object-Oriented Analysis and Design with UML
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
check out my earlier post on exporting to SYLK format a week or so ago.
http://www.coderanch.com/forums/


42
Stephen Huey
Ranch Hand

Joined: Jul 15, 2003
Posts: 618
We look at CSV files in Excel all the time. In fact, Excel assumes any file with a .csv extension to contain comma-separated values. It's easy to create one. The basic idea is that commas serve as delimiters and each row begins a new record.
In English, that means that if I want to save some address info into a CSV file, then in a text editor like Notepad, the data will look like this:
John Smith, 42 Main St, Houston, TX, 77005
Frank Jones, 19 Timberlake, Evanston, IL, 60201
Each field is separated by a comma, and each record begins on a new row/line. Excel will display each field in its own cell automatically. Now, what happens if a field contains a comma? How would you handle John Smith, Jr.? Simple, with double quotes:
"John Smith, Jr.", 42 Main St, Houston, TX 77005
Try to make the file in Notepad, save it with a .csv extension, and then double-click it and Excel will probably be chosen to open it. If not, then just open it in Excel and you'll see that the values don't all get lumped into the first cells.
As you can imagine, it's easy to write out to a text file in CSV format using basic Java IO stuff.
God bless,
Stephen
Anant Kadiyala
Greenhorn

Joined: Aug 29, 2001
Posts: 24
Thanks for the posts.
If I were to save the data as a .csv file, is there a way to specify simple Excel formatting (like displaying simple column header names, etc in Excel)?
It is a simple table, but the Excel sheet should not be mere dump of the data. The requirement is that it should be presented in a decent format to the user.
Thanks,
Anant
Brian Showalter
Greenhorn

Joined: Sep 20, 2002
Posts: 3
Originally posted by Anant Kadiyala:
I have a web page (JSP) that renders some data in HTML tables. We would like to have an �export to Excel button� on the page. What is the best way to export HTML data from JSP into an Excel file?

You could write a servlet that uses the Jakarta POI library (http://jakarta.apache.org/poi/) to build the Excel spreadsheet. I am currently using POI to generate several Excel files, and it works very well.
Brian
Ben Dover
Ranch Hand

Joined: Jan 30, 2004
Posts: 91
Originally posted by Brian Showalter:

You could write a servlet that uses the Jakarta POI library (http://jakarta.apache.org/poi/) to build the Excel spreadsheet. I am currently using POI to generate several Excel files, and it works very well.
Brian

What excactly does POI stand for?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving data to Excel files
 
Similar Threads
How to Open Excel file from JSP page.
Import from and export to Excel
Exporting HTML-Table data to EXCEL sheet
importing data from jsp to excel to generate image in Excel
How to export data in excel