Thursday, October 6, 2011

Output ColdFusion database query as Excel file with filename specified

I guess the title of this post tells it all.  And really, it is no different from your normal ColdFusion queries except that you add in the first two lines at the top.

You can refer to Adobe's docs on this as well.

<cfcontent type="application/msexcel">
<cfheader name="content-disposition" value="attachment;filename=customers.xls">

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">



<cfquery name="getcustomers" datasource="custDB" dbtype="ODBC" >
select * from customers where companyid='#companyid#'


<table width="100%" border=1>
<th>Customer name</th>
<th>Customer email</th>

<cfoutput query="getcustomers">


Pin It

No comments:

Post a Comment