<

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x

How To generate DOC Using Coldfusion

Published on
9,018 Points
2,818 Views
2 Endorsements
Last Modified:
Approved
The technique is by far very Simple!

How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet with you guys how did I do that.   Using a simple technique to make work from query to DOC using Coldfusion:

Here is the coding sample…

In the code below, we are using the component where we are fetching the query results and putting them in the endUsers variable.  Now we run a simple query and below running will generate the code as we expected.

The below code is provided with the HELP of SidFishes (an EE Coldfusion Expert)
<cfset tools = CreateObject("component",".tools")>
<cfset endUsers = #tools.UsersArea()#>
<cfset ExcelFileName = "#DateFormat(Now(), 'mmddyyyy')#.doc">
<cfcontent type="application/msword">
<cfheader name="Content-Disposition" value="filename=menu_#ExcelFileName#">
<cfoutput query="endUsers">
<table cellpadding="0" cellspacing="0" border="1">
   <tr>
      <th>Created By</th>
      <th>Created Date</th>
      <th>Status</th>
   </tr> 
   <tr>
      <td>#endUsers.firstname#</td>
      <td>#endUsers.lastname#</td>
      <td>#endUsers.nemail#</td>
    </tr>
   </table>
</cfoutput>

Open in new window


This may not be the best technique but it works.  Another technique of doing the same is which I tried my way is listed below:

<cfset tools = CreateObject("component",".tools")>
<cfset endUsers = #tools.UsersArea()#>
<cfsavecontent variable="docfile">
<table border="1">
  <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>Email Address</th>
  </tr>
  <cfoutput query="endUsers">
    <tr>
      <td>#endUsers.firstname#</td>
      <td>#endUsers.lastname#</td>
      <td>#endUsers.nemail#</td>
    </tr>
  </cfoutput>
</table>
</cfsavecontent>
<cfheader name="content-disposition" value="inline;filename=ToDoc.doc">
<cfcontent type="application/msword" >
<cfoutput>#docfile#</cfoutput>

Open in new window


That’s Pretty Simple Techniques, try it and You will be amazed to see its results! The technique we presented is far by very basic technique. Although there are many custom tags available which can by far generate good results through the use of CSS and many HTML Tag.  But they are paid ones!

This is the simple technique in which we can generate our result in the doc File!  For quick view.  If you are not really serious about the formatting and want to show it as simple and as fast you can. Try the technique which suits you and enjoy.
2
0 Comments

Featured Post

Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

Wrapper-1-Query. Use an Excel function to calculate a column for an Access query. Part 1. Shows a query in Access that has a calculated column with the results of an Excel worksheet function. See how to call a wrapper function from a query, and …
Microsoft Office 365 Backup and Restore Solution by SysTools to export Office 365 mailbox to PST / EML file format on Windows OS. On Mac, tool backup O365 to PST / MBOX / MSG / EML / EMLX file formats. Not only this, restore option helps to import s…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month