0

I am trying the last two weeks to convert a query data to ms word doc using Coldfusion.The only approach that i have found is:

<cfcontent type="application/msword">
    <cfquery name="getArtist" datasource="cfartgallery">
    SELECT *
    FROM Artists
    </cfquery>

    <cfdump var=#getArtist#>

The above is converting the query in doc (you can open it as doc) but if you skip to open the file and directly save it the only way that you can save it is as a ".cfm". This is not what i need. I am trying to build an app that users can download articles in ms word files. Pdf is not an option.

Thank you in advance and be well,

Tom

  • 4
    You are very mistaken. `` does *not* make ColdFusion produce MS Word files. This is like assuming `` would make CouldFusion produce .exe files. – Tomalak May 20 '12 at 19:57
  • 2
    To explain: `` produces HTML. Setting the HTTP content-type to `"application/msword"` makes the browser open MS Word instead of displaying the page by itself. MS Word just happens to understand HTML. At no point in this chain of events an actual MS Word file is produced. That you have something that kind-of works is nothing but an accident. Look here for some hints: http://stackoverflow.com/questions/3456413/ – Tomalak May 20 '12 at 20:05
  • Thank you for reply. I saw the link that you send me. I have a question. Where do yo place the query? I shan't to produce doc dynamically from a db. Many thanks my friend –  May 20 '12 at 21:41
  • 1
    Tom, the quick answer is "wherever you like before it's needed", but read about [MVC](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller), and investigate [FW/1](https://github.com/seancorfield/fw1) - these will provide a structure that helps you to better organise all your code, whilst also answering most "where does X goes" questions. :) – Peter Boughton May 20 '12 at 23:16
  • 3
    Re *the only way that you can save it is as a ".cfm"..* If you wish to specify an alternate file name, you need to use `cfheader` to set the `Content-Disposition` header. It defaults to the script generating your faux MS Word document. (See [examples at the end of this page](http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c82.html) for an example.) Keep in mind that simply changes the file name displayed in the "save as" dialogue. As Tomalak mentioned, it does not magically transform your output into a valid MS Word file. The content is still just html. – Leigh May 21 '12 at 08:15

1 Answers1

0

Use cfdocument to output it as a pdf. This should work ok and open easily in MS Word or elsewhere.

<cfdocument 
    format="pdf" 
    filename = "pdfpath\pdffile.pdf"
    overwrite = "yes"
    marginBottom = ".2"
    marginLeft = ".4"
    marginRight = ".4"
    marginTop = ".2">

    Blah blah stuff here...

</cfdocument>

Edit: Sorry, I missed your note that PDF is not an option.

Leigh
  • 28,765
  • 10
  • 55
  • 103
Merle_the_Pearl
  • 1,391
  • 3
  • 18
  • 25