Output excel file easy with ColdFusion MX.
Hi Many years ago i wrote an article here to create an excel CSV file with ColdFusion.
I wanted to update this with the newer easier way to accomplish the same goal.
have a search page with an output type drop box called "otype" values("web","xls","prt")
Write out your page in an HTML table with the columns you want in excel.
Then put an IF statement around your table or simply at the bottom of the page with links to the same page with the otype or a form that submits to the same page with the otype var.
then use this code:
Terms of Agreement:
By using this article, you agree to the following terms...
You may use
this article in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
You MAY NOT redistribute this article (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
You may link to this article from another website, but ONLY if it is not wrapped in a frame.
You will abide by any additional copyright restrictions which the author may have placed in the article or article's description.
<cfif #form.otype# EQ "xls">
<cfheader
name="Content-Type"
value="application/msexcel">
<cfheader
name="Content-Disposition"
value="attachment; filename=MyReport.xls">
<cfelseif #form.otype# EQ "prt">
<cfheader
name="Content-Type"
value="application/msword">
<cfheader
name="Content-Disposition"
value="attachment; filename=MyReport.doc">
</cfif>
Thats it, very simple and when the link is clicked or form is submited, the user will be asked to download the Excel file.
good (If this comment was disrespectful, please report it.)
Add Your Feedback
Your feedback will be posted below and an email sent to
the author. Please remember that the author was kind enough to
share this with you, so any criticisms must be stated politely, or they
will be deleted. (For feedback not related to this particular article, please
click here instead.)