my dog learned polymorphism*
The moose likes Servlets and the fly likes Can Servlet out data as MS-WORD format? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can Servlet out data as MS-WORD format?" Watch "Can Servlet out data as MS-WORD format?" New topic
Author

Can Servlet out data as MS-WORD format?

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
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.


Thanks everyone who helped me
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Try setting the content type of the response to application/msword. I haven't tried it, but it is a standard content type.


Matthew Phillips
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
Is it possible to format the WORD/Excel files? Or just attach a plain text on those files? Thanks!
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
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


Malhar Barai
SOA & Java Book
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
Oh, thanks. Let me try.
Juanjo Bazan
Ranch Hand

Joined: Feb 04, 2002
Posts: 231
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

Joined: Jan 23, 2002
Posts: 139
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

Joined: Nov 26, 2002
Posts: 2
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can Servlet out data as MS-WORD format?