Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1006
  • Last Modified:

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 ?
0
cofactor
Asked:
cofactor
  • 9
  • 9
  • 3
  • +1
1 Solution
 
Gene_CypCommented:
Hmm, not sure what you are getting at. You don't like those frames?
0
 
cofactorAuthor Commented:
>>>You don't like those frames?

Yes.  
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
CEHJCommented:
>>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
0
 
CEHJCommented:
And if you use RTF, then you can use Apache FOP to write it
0
 
objectsCommented:
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

0
 
cofactorAuthor Commented:
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;");
0
 
cofactorAuthor Commented:
>>>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 ?
0
 
CEHJCommented:
>>'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?
0
 
CEHJCommented:
If it's tabular data, the easiest option would be csv, which would open by default in Excel, yet is a portable format
0
 
cofactorAuthor Commented:
>>>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.
0
 
cofactorAuthor Commented:

>>>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.
0
 
CEHJCommented:
Here's a tutorial to produce a table in a doc (can be exported as one) using OpenOffice api:

http://openofficejava.blogspot.com/
0
 
cofactorAuthor Commented:
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 ?
0
 
CEHJCommented:
afaik no, since there's a commercial tool available to generate Word from Jasper
0
 
CEHJCommented:
The last link i posted does exactly what you need
0
 
cofactorAuthor Commented:
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 ?

0
 
CEHJCommented:
>>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
0
 
objectsCommented:
where are you getting the jasper report from?
0
 
cofactorAuthor Commented:
Here I have a workaround. I changed this way..

step1:  made a template doc   abc.doc

step2:  save this doc  as HTML using  MSWORD

step3: rename this html to a jsp

step3:  replace all the hard data with jsp scriplets

step4:  put these lines at the top

<%
response.setContentType("application/doc");
response.setHeader("Content-disposition","attachment; filename=abc.doc;");
%>


This will throw a doc download prompt . This  will not tamper the exported doc format ...this works fine.

0
 
objectsCommented:
good work, using simple html like that should work fine for you :)
0
 
cofactorAuthor Commented:
I figured out solution myself
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 9
  • 9
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now