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">

<html>
<head>
<title>Customers</title>
</head>

<body>

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

<h1>Customers</h1>

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

<cfoutput query="getcustomers">
<tr>
<td>#customername#</td>
<td>#customeremail#</td>
</tr>
</cfoutput>

</table>

</body>
</html>

Comments

Popular posts from this blog

How to create an organizational chart in your webpage using Google Organization Chart Tools

Embed JSX code with if condition in React app