Skip to main content
Known Participant
August 26, 2010
Answered

exporting data to Word with Coldfusion

  • August 26, 2010
  • 1 reply
  • 4749 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.

-__cfSearching__-Correct answer
Inspiring
August 26, 2010

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