<

How To generate DOC Using Coldfusion

Published on
8,843 Points
2,643 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Join & Write a Comment

this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month