Link to home
Start Free TrialLog in
Avatar of FastEddie___
FastEddie___

asked on

Export HTML page to MS Word using Coldfusion 8

I'm able to export a page to MS Word doc but the result is the html markup and not the html display.
Could I get some advice on how to fix this?

Here is what I'm using:
---------------------------------
      <cfheader name="content-disposition" value="inline;filename=ToDoc.doc">
        <cfcontent type="application/msword">

          <cfsavecontent variable="docfile">
                   <cfinclude template="SOME_WEB_PAGE_content.cfm" />
          </cfsavecontent>

           <cfoutput>#docfile#</cfoutput>
---------------------------------

I'd like to be able to stream a webpage to a browser and have the user download it in MS Word format.

What is currently being returned is the html markup.
The page is returning the correct data from the database but it's all in markup like:

...
<table>
<tr>
<td>User Name</td>
<td>Mr. Wonderful</td>
</tr>
</table>
...

Any advice on how to correct this?
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

You have to name it "ToDoc.html" for Word to 'interpret' it like a web page would.
ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of FastEddie___
FastEddie___

ASKER

@DaveBaldwin - I changed "ToDoc.doc" to "ToDoc.html" but it still did not work.

@Agx - Yes you are correct, There is a lot more than that table. I'll supply the output that get produced in an attachement.
              Please note that I'm setting the header first then including the web page.

Any suggestions?
Here is the attachemnt:
 

index.txt
Also please note that I don not have MS Word installed on the web server and
I get this error message when I try to export the file on the browser:
     "Word cannot start the converter mswrd632.wpc."
 
 
> Please note that I'm setting the header first then including the web page.

Yeah, so is my example.  I just moved the cfsavecontent to make sure nothing was interfering with the generated output.

First -  do you have CF debugging enabled? That can mess up downloads because it adds extra output to the content sent to the browsers.  

Second - For anything beyond the very basics, you'll probably need more formal html syntax ie <html><head> <body>, etc... tags.  I don't see those in the attachment.
BTW: You should really start with something MUCH simpler than the CSS you have right now. A lot depends on how well MS Word interprets the html/css.  (Almost certainly, it won't be able to interpret really advanced stuff).  If css really is what's causing the problems, it will be hard to pinpoint within so much code.

I'd comment out the CSS and try it with just the basic html output. If that works, start adding back pieces of the css until it either works or chokes again.
<html>
<body>
    ...rest of output ....
</body>
</html>
>  ... than the CSS you have right now

Hm... that's assuming the css IS your's and not from CF's debugging output - that is.
That example is not a valid web page to start with.  My copy of Word won't open that as HTML anyway.
Thanks agx.

Debug is enabled but it did not cause the problem.
I changed the savecontent part to
          <cfsavecontent variable="docfile">
              <html>
               <head>
               </head>
               <body>
              <cfinclude template="SOME_WEB_PAGE_content.cfm" />
               </body>
               </html>
          </cfsavecontent>
 and the page is being exported to MS Word fine but the images are not being displayed.

Is there any way of including the images as well?
Hope I'm not asking for too much with the images?
 
Your right Dave that page was used as an include and so the header and footer was left off of it.

Adding the <html><head><body> tags to cfsavecontent works for the most part.
Any ideas on dealing with images when doing something like that?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you.