wood burning stoves 2.0*
The moose likes Servlets and the fly likes How to view XLS documents loaded from database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to view XLS documents loaded from database" Watch "How to view XLS documents loaded from database" New topic
Author

How to view XLS documents loaded from database

sahidul karim
Greenhorn

Joined: Sep 19, 2006
Posts: 28
How can i display values as a XLS file from database using servlet.That XLS file has a specific format and already its uploded in a specific folder location.I want to display data in specific filed in that XLS.
[ November 26, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61084
    
  66

Is the XLS data in a file or in the database? Your post is not clear.

In either case, your servlet will obtain the data (either from the DB or by reading it from the file) and stream it to the response. Be sure to set the approriate repsonse headers before streaming the data.

Search this forum for previous discussions on setting the headers. Search for terms such as "context-type" and "content-disposition".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sahidul karim
Greenhorn

Joined: Sep 19, 2006
Posts: 28
XLS data is in database.ya i have written proper content type.I am also getting data in XLS
sahidul karim
Greenhorn

Joined: Sep 19, 2006
Posts: 28
but i want to get it in a specipic column .suppose in my XLS first three line is some text line which is fixed in that XLS. now i am retrieving employee id and name from database. i want to display these after first three rows and after that employee id will be 2nd column and employee name will be in 5th column.how to achieve this?
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
Hi -

If your web server happens to be a Windows PC, you can read your .xls spreadsheet directly from JDBC:
http://www.javaworld.com/javaworld/javaqa/2001-06/04-qa-0629-excel.html

Otherwise, the folks you brought you Apache and Tomcat have a library, "POI", especially for reading and writing Excel files:
http://jakarta.apache.org/poi/

'Hope that helps .. PSM


Paul M. Santa Maria, SCJP
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Have a look at this thread. I have already posted code which reads XLS file from server and send as a response to client in XLS format.

hth,


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
Paul Santa Maria
Ranch Hand

Joined: Feb 24, 2004
Posts: 236
sahidul -

Prabhu's code simply returns the binary file data from the server to the client. If that's all you need - great! But otherwise, if you need to interpret the data (or, more importantly, if you need to interpret the spreadsheet data without having to buy a copy of M$ Office), then my link is applicable.

'Hope that helps .. PSM
[ November 26, 2006: Message edited by: Paul Santa Maria ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to view XLS documents loaded from database