How To generate DOC Using Coldfusion

AID: 3141
  • Status: Published

1620 points

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>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen 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>
                                    
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:

Select allOpen 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.
Asked On
2010-05-21 at 03:45:17ID3141
Tags

Coldfusion

,

DOC

Topic

Cold Fusion Markup Language

Views
1049

Comments

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top ColdFusion Language Experts

  1. _agx_

    268,859

    Guru

    2,000 points yesterday

    Profile
    Rank: Genius
  2. gdemaria

    184,144

    Guru

    1,800 points yesterday

    Profile
    Rank: Genius
  3. SidFishes

    87,866

    Master

    2,000 points yesterday

    Profile
    Rank: Genius
  4. myselfrandhawa

    58,872

    Master

    0 points yesterday

    Profile
    Rank: Guru
  5. dgrafx

    36,068

    0 points yesterday

    Profile
    Rank: Sage
  6. pravinasar

    26,318

    0 points yesterday

    Profile
    Rank: Genius
  7. leakim971

    19,600

    0 points yesterday

    Profile
    Rank: Genius
  8. maestropsm

    15,340

    0 points yesterday

    Profile
    Rank: Guru
  9. ansudhindra

    13,300

    0 points yesterday

    Profile
    Rank: Wizard
  10. Zvonko

    12,264

    0 points yesterday

    Profile
    Rank: Genius
  11. micropc1

    10,200

    0 points yesterday

    Profile
    Rank: Master
  12. COBOLdinosaur

    9,800

    200 points yesterday

    Profile
    Rank: Genius
  13. TechHelpr08210

    9,700

    0 points yesterday

    Profile
  14. cyberdyne_dev

    9,500

    0 points yesterday

    Profile
  15. srikanthmadishetti

    8,601

    0 points yesterday

    Profile
    Rank: Guru
  16. brijeshchauhan

    8,468

    0 points yesterday

    Profile
    Rank: Guru
  17. Proculopsis

    8,200

    0 points yesterday

    Profile
    Rank: Sage
  18. kaufmed

    7,468

    0 points yesterday

    Profile
    Rank: Genius
  19. JohnHowlett

    6,000

    0 points yesterday

    Profile
  20. DaveBaldwin

    5,750

    0 points yesterday

    Profile
    Rank: Genius
  21. digicidal

    4,600

    0 points yesterday

    Profile
    Rank: Guru
  22. erikTsomik

    4,500

    0 points yesterday

    Profile
    Rank: Sage
  23. HainKurt

    4,500

    0 points yesterday

    Profile
    Rank: Genius
  24. mplungjan

    4,400

    0 points yesterday

    Profile
    Rank: Savant
  25. sedgwick

    4,000

    0 points yesterday

    Profile
    Rank: Genius

Hall Of Fame