Render data as a document for external use, e.g. Word

I am pulling some content from a database call and generating the MS
Word content via a cfsavecontent (doing variable replacement) and need
to have it open as a Word document.

Not sure best way to do that via framework.


As a general rule, I do this sort of thing through the following method:

1. Generate the data that you'll need for the document creation in
your handler. Something like rc.mydata = functiontogetstuff();
2. Use a view that knows how to take the data and create the document
you want. Render that view into a variable in your handler using
something like rc.contentToDisplay = RenderView('myMSWordDoc');
3. At that point you should have the MS Word doc (or PDF or Excel or
what have you) all done and stuffed into the rc.contentToDisplay
variable. Then you could either save it to disk, email it off, or use
<cfheader> to change the content type and content disposition of the
request response going back to the browser.

Hope that helps,

Take a look the Utility plugin.

ALso note that the event.renderdata() method can take a contenttype and deliver content also. Since you already converted the data the type would be “plain”.

So you can do this:


And that’s it.

Thanks all for the options