<

How To generate DOC Using Coldfusion

Published on
8,934 Points
2,734 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
Comment
0 Comments

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Join & Write a Comment

Did you know PowerShell can save you time with SaaS platforms? Simply leverage RESTfulAPIs to build your own PowerShell modules. These will kill repetitive tickets and tabs, using the command Invoke-RestMethod. Tune into this webinar to learn how…
A query can call a function, and a function can call Excel, even though we are in Access. This is Part 2, and steps you through the VBA that "wraps" Excel functionality so we can use its worksheet functions in Access. The declaration statement de…

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month