Solved

export to doc

Posted on 2011-03-07
24
917 Views
Last Modified: 2012-06-27
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
Comment
Question by:cofactor
  • 9
  • 9
  • 3
  • +1
24 Comments
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35066973
Hmm, not sure what you are getting at. You don't like those frames?
0
 

Author Comment

by:cofactor
ID: 35067089
>>>You don't like those frames?

Yes.  
0
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35067200
0
 
LVL 7

Expert Comment

by:Gene_Cyp
ID: 35067221
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068037
>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068049
And if you use RTF, then you can use Apache FOP to write it
0
 
LVL 92

Expert Comment

by:objects
ID: 35068072
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
 

Author Comment

by:cofactor
ID: 35068324
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068347
0
 

Author Comment

by:cofactor
ID: 35068374
>>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068407
>>'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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068410
If it's tabular data, the easiest option would be csv, which would open by default in Excel, yet is a portable format
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:cofactor
ID: 35068415
>>>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
 

Author Comment

by:cofactor
ID: 35068442

>>>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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068503
Here's a tutorial to produce a table in a doc (can be exported as one) using OpenOffice api:

http://openofficejava.blogspot.com/
0
 

Author Comment

by:cofactor
ID: 35068571
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068590
afaik no, since there's a commercial tool available to generate Word from Jasper
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 35068601
The last link i posted does exactly what you need
0
 

Author Comment

by:cofactor
ID: 35068778
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 35069400
>>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
 
LVL 92

Expert Comment

by:objects
ID: 35074975
where are you getting the jasper report from?
0
 

Accepted Solution

by:
cofactor earned 0 total points
ID: 35092267
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
 
LVL 92

Expert Comment

by:objects
ID: 35092394
good work, using simple html like that should work fine for you :)
0
 

Author Closing Comment

by:cofactor
ID: 35126479
I figured out solution myself
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now