Link to home
Create AccountLog in
Avatar of cofactor
cofactor

asked on

export to doc

I want to export jsp data to a word doc.

I have the following

result.jsp
------------
 <%
response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");
// table
// tr , td etc
%>

It export the doc file but  the doc file does not look clean .

Look the screenshot of the doc I have.(attached)
 export.zip

What are the changes I need to do ?
Avatar of Gene_Cyp
Gene_Cyp

Hmm, not sure what you are getting at. You don't like those frames?
Avatar of cofactor

ASKER

>>>You don't like those frames?

Yes.  
Avatar of CEHJ
>>It export the doc file but  the doc file does not look clean .

Unless you're then writing a word format document to the output stream, that's not going to work. You'll need to use an api such as the OpenOffice UNO api that can convert to word. Better still, use a portable format that could be opened in Word, such as RTF
And if you use RTF, then you can use Apache FOP to write it
problem with the approach you are using is that you will lose a lot of the styling so is only suitable for fairly simple pages

you'll find a few other options here
http://stackoverflow.com/questions/32151/best-way-to-export-html-to-word-without-having-ms-word-installed

surprisingly , I also exported many excels this way earlier...why the doc export does not work in the same fashion  ?

>>>Better still, use a portable format that could be opened in Word, such as RTF
>>>And if you use RTF, then you can use Apache FOP to write it

Could you please provide me a quick tutorial so that I can make it .
Also , what would be content type to be set for RTF in the response ?

Is it like this ?
response.setContentType("application/RTF");
response.setHeader("Content-disposition","attachment; filename=abc.RTF;");
>>>you'll find a few other options here

Ok .Let me tell you how I doing it right now..


my jsp   result.jsp   has a button 'Export to Word'  ..when I click on it , I call another jsp export.jsp  which has the same code as similar to result.jsp  with extra two lines at the top i.e
 <%
response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");
// table
// tr , td etc
%>

This is to throw a word doc download prompt. But as you see the exported doc has become unclean.

What are the other options ,I can think of at this point ?
>>'Export to Word'

As i mentioned, that would have to produce the correct binary (or xml depending on the version) file that is the Word format. Is that what you're doing?
If it's tabular data, the easiest option would be csv, which would open by default in Excel, yet is a portable format
>>>See http://xmlgraphics.apache.org/fop/0.95/output.html#rtf

This looks complicated. I dont see any code writing tutorial . searched google but did not find any material where I can get a sample.

>>>If it's tabular data

yes. its a tabular data.

>>>the easiest option would be csv

I understand . but requirement is to export to a doc file.  what ever the html table is seen in the page thats to be exported into a doc.
Here's a tutorial to produce a table in a doc (can be exported as one) using OpenOffice api:

http://openofficejava.blogspot.com/
Can jasperReport be used to generate doc for my system ? but  JasperReport accept HashMap to push param , value .....However, I  use a iterator in jsp to make a tabular data...I dont have hashmap .

So, Is there any chance to use JasperReport / Ireport for my system  ?

Also , can they be used to throw download prompt ?  what I found is , they are used to dump report files....so, is it possible  to throw download prompt  if I use JasperReport ?
afaik no, since there's a commercial tool available to generate Word from Jasper
The last link i posted does exactly what you need
jasperreport can be used to generate Report output in  RTF  ..right ?  As you suggested RTF also a kind of doc.?

problem with open office is:

they put few restrictions ..

Before you begin you need to install openoffice.org  // this means you need to install openoffice in the server.

You also need the program directory on your class path // did not like this dependency.

If I make a jasperreport RTF output , can it be published to a doc by using third party software later on if I wish ?

>>If I make a jasperreport RTF output , can it be published to a doc by using third party software later on if I wish ?

Yes and it should open by default in Word anyway, so they might not even realise it's not a Word doc
where are you getting the jasper report from?
ASKER CERTIFIED SOLUTION
Avatar of cofactor
cofactor

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
good work, using simple html like that should work fine for you :)
I figured out solution myself