title: How can I force a download of a generated Excel file and still save a copy?
body: <p>I have a code I based off of this:</p>
  
  <p><a href="https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-s/spreadsheetaddrows.html" rel="nofollow">https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-s/spreadsheetaddrows.html</a></p>
  
  <p>It currently generates an Excel file, saves it on the server, then offers a link to the excel file.</p>
  
  <p>Here is my current code for <strong>report.cfm</strong>:</p>
  
  <pre><code>&lt;cfset todayDate = Now()&gt; 
  &lt;cfscript&gt;
         // Get data from a query
         Applicants=QueryExecute("
  
              SELECT *
              FROM dbo.applicants
              ORDER BY lastname ASC
  
                                 ",[],{datasource="DATABASE"});
         // Create a spreadsheet object with sheetname
         spObj=spreadsheetNew("Applicants",true);
         // Add rows with data from query result. The data start from row 1, col 1. The spreadsheet
         // will have column names.
         spreadsheetAddrows(spObj,Applicants,1,1,true,[""],true);
         dirName=GetDirectoryFromPath(GetCurrentTemplatePath());
         // Write spreadsheet to a file
         SpreadsheetWrite(spObj,"#dirName##dateformat(todayDate, "yyyymmdd")#_#TimeFormat(todayDate, "HHmmss")#_Applicants.xlsx",true);
         //SpreadsheetWrite(spObj,"#dirName##DateFormat(todayDate, "yyyymmdd")#_Applicants.xlsx",true);
  &lt;/cfscript&gt;
  &lt;cfoutput&gt;
      &lt;a href="#dateformat(todayDate, "yyyymmdd")#_#TimeFormat(todayDate, "HHmmss")#_Applicants.xlsx"&gt;Click to download your Excel File&lt;/a&gt;
  &lt;/cfoutput&gt;
  </code></pre>
  
  <p>How can I change it so when a user clicks on the link for <strong>report.cfm</strong> it will not present them <em>"Click to download your Excel File"</em> anymore, but automatically trigger the download AND keep a copy of the generated Excel file?</p>
  
  <hr>
  
  <p>Follow-up:</p>
  
  <p>I present a link to the user - "generate last year's report"
  This links to report.cfm which, as it is right now, generates the excel file and presents them with the download link.</p>
  
  <p>They do not want that extra click so I'm looking for a solution where the page downloads the file automatically.</p>
  
  <p>With Bernhard's suggestion, I revised my code to this</p>
  
  <pre><code>&lt;cfscript&gt;
     - original script -
  &lt;/cfscript&gt;
  &lt;cfheader name="Content-Disposition" value="attachment; filename=#dateformat(todayDate, "yyyymmdd")#_#TimeFormat(todayDate, "HHmmss")#_Year2013GradApps.xlsx"&gt;
  &lt;cfcontent type="application/vnd.msexcel"&gt;
  </code></pre>
  
  <p>I am able to force the download, but Excel cannot open the file "because the file format or file extension is not valid."</p>