Skip to main content
Known Participant
August 26, 2010
Answered

exporting data to Word with Coldfusion

  • August 26, 2010
  • 1 reply
  • 4725 views

Saw the link at

http://www.irt.org/articles/js154/index.htm which explains how to do it.

But, my need is a bit more than what is shown.

I have to run a query and based on results of it decide what should be a row title, then display its value. Something like

<cfquery name="getDepartments" datasource="#Application.ds#">
                    SELECT *
                    FROM departments
                    WHERE deptID = '#form_data.deptID#'
                </cfquery>

then

<table width="100%" border="1" rules="all" cellpadding="5px" cellspacing="0px" style="width:100%; font-family:Arial, Helvetica, sans-serif; font-size:12px;">
                            <tr>
                                <td style="font-family:Arial; font-size:12px;"><b>

<cfif getDepartments.DEPT_TYPE is 'AP'>
                                        Corporate
                                    <cfelse>
                                        Retail
                                    </cfif>
                                    :</b>
                                    <br>

This does not work using the method shown at the link http://www.irt.org/articles/js154/index.htm

How can I achieve what I want?

Any advice would be welcome.

This topic has been closed for replies.
Correct answer -__cfSearching__-

Well, the two formats are totally different. I do not think you can mix the two. So either you are trying to create an rtf file or an html file.

Most versions of MS Word are capable of interpreting/displaying html. So unless you specifically need an rtf file, it is easier to just generate plain html. Then use cfheader and cfcontent to indicate the document should be opened with MS Word. There is an example for Excel at the bottom of this page. But the same concept applies to Word files. Just use the correct mime type and file name.

http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Tags_c_11.html

1 reply

Inspiring
August 26, 2010

This does not work

What do you mean by "does not work"?

What results are you expecting, and how do the actual results differ?

h_c1Author
Known Participant
August 26, 2010

Thanks for the response. I should have been more clear in my first post.

The parsing fails because of the HTML table formatting which I need. Because the method shown at http://www.irt.org/articles/js154/index.htm is shown for values already present, not something which is done dynamically using that results with table formatting is done. In other words, the link shows something like Personnel name #PersonnelName#

I need something like if personnel exists then show a table row with cellpadding/cell spacing, display personnel name in a particular font size and name.

Results I am expecting are if a record exists in my table, I should be able to display it with HTML table formatting. This is not happening as the mixture of the code used for RTF and HTML table is throwing off the parsing.

New Participant
September 30, 2021
As I mentioned before, most versions of MS Word can interpret html.  So theoretically you could just use the same html, but add cfheader and cfcontent to trick the browser into thinking it is a Word document. Be sure to give it a *.doc extension.  MS Word should then treat the file as if it really were a regular Word document.  That is probably the simplest option.  (See the link in my previous response for an example.)

I will try doing that and see how it works out. Thanks for your suggestions and time. I have marked as your answer as helpful for your advice.


I am having similar issue - the link does not exists anymore . Could you please help .