Reputation: 1583
The following two lines of code are responsible for forcefully downloading the MS Excel file:
<CFHEADER NAME="Content-Disposition" VALUE="inline; filename=stats.xls">
<cfcontent type="application/msexcel"><cfoutput>#Query2Excel(qONEQUERY)#</cfoutput>
How can I avoid that from happening? I would like to this happen when a user clicks on a download button.
Please let me know how to approach. Thanks
Upvotes: 0
Views: 543
Reputation: 28873
(Scott already answered you, but since I already had this written ...)
I would like to this happen when a user clicks on download button
Um.. then create a link or button that redirects to your "download" page:
<a href="downloadFauxExcelFile.cfm">Download</a>
A couple things to keep in mind:
Query2Excel
generates HTML which MS Excel can interpret, but technically is not a true Excel file (See Excel file formats). Due to Excel's Extension hardening, some versions of Excel will display a warning when the user attempts to open the faux-Excel file. The only way to avoid it by ensuring the file extension matches the content, such as:
cfspreadsheet
.csv
extension in cfheader
value="inline;..."
means display the file in the current browser window (not prompt to download). Note, you cannot force the file to be displayed "inline". The behavior is determined by the client. If the browser is configured to open that particular file type, it will. Otherwise, the browser will display a "save as" dialog box and prompt the user to save or open the file.
Upvotes: 2
Reputation: 7519
Simply have the button point to a page where those two lines are executed.
Upvotes: 3