Question

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

Was it helpful?

Solution

Simply have the button point to a page where those two lines are executed.

OTHER TIPS

(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:

    1. Use the POIUtility.cfc to generate a true Excel file, or for CF9+ use cfspreadsheet
    2. Generate a plain CSV file instead. Be sure to use the .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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top