Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to view XLS documents loaded from database

 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65111
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XLS data is in database.ya i have written proper content type.I am also getting data in XLS
 
sahidul karim
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
 
Paul Santa Maria
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic