This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Servlet out data as MS-WORD format?

 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,
I would like a servlet get data from DB and format the data, then output as a word file when user click on the link, is it possible? Thanks.
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try setting the content type of the response to application/msword. I haven't tried it, but it is a standard content type.
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to format the WORD/Excel files? Or just attach a plain text on those files? Thanks!
 
Malhar Barai
Author
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Shamrock:
Is it possible to format the WORD/Excel files?

well dear
You can surely format them, in case of Excel, set the proper content type & while outputting the data, dont start with standard HTML tags but only start with "<table><tr><td>" & so on...
this will help you to format the Excel tables...
with WORD you can format as standard text.
hth
MB
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, thanks. Let me try.
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a jakarta project called POI.
It's a java API for manipulating MS file formats.
It include several subprojects, like the Horrible Document Format (For MS-WORD format) and the Horrible Spreadsheet Format (for Excel files).
You can find more info in the POI website:
http://jakarta.apache.org/poi/
For manipulating Excel files, there is another solution:
You can do it using JDBC. MS provides an ODBC driver for Excel, so you can use JDBC and the Sun JDBC-ODBC driver to read Excel files.
Check the Javaworld Java/Microsoft Excel series:
http://www.javaworld.com/javaworld/javaqa/2001-06/04-qa-0629-excel.html

HTH
 
Ken Shamrock
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
I've tried output simple information as XLS or WORD doc. (It's Strange that with <html> I can still the displayed format in the xls file)
Another idea comes, you know, an excel file can consist of several spreadsheets, if I want to do this, must I need to use the POS mentioned by Juanjo Bazan ? Thanks
 
yaso sandra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also need a servelt to generate a word doc.
It did when i set the contenttype to
application/msword .But when it got saved it dint save with a .doc.I had to open with ms word.
.I need it to have .doc format so that i can print it. do help.
thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic