title: Preview spreadsheet prior to excel download ColdFusion 11
body: <p>I'm trying to export data from a query to an excel spreadsheet.  I used the following code to successfully download an HTML table to a spreadsheet via Chrome and IE (picked up from Raymond) but I am now looking for a way to display the data prior to download.  Currently this immediately downloads when the submit button is selected.</p>
  
  <p><a href="https://i.stack.imgur.com/GO9RA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GO9RA.png" alt="enter image description here"></a></p>
  
  <pre><code>&lt;cfset request.isIE = false /&gt;
  &lt;cfif cgi.http_user_agent contains "MSIE"&gt;
   &lt;cfset request.isIE = true /&gt;
  &lt;/cfif&gt;
  
  &lt;cfheader name="Content-Disposition" value="inline; filename=SearchResults.xls"&gt;
  &lt;cfcontent type="application/vnd.ms-excel"&gt;
  &lt;cfset ThisOrganism="#Form.GenusSpecies#"&gt;
  
  &lt;cfquery name="BSAFbyOrganism" datasource="BSAFweb"&gt;
  SELECT ID, StudyType, Chem_Name
  FROM Summary
  WHERE   GenusSpecies='#ThisOrganism#'
  ORDER BY Chem_Name
  
  &lt;/cfquery&gt;
   &lt;table width="100%" border="1" cellpadding="5px"&gt;
     &lt;tr&gt;
       &lt;th&gt;ID&lt;/th&gt;
       &lt;th&gt;StudyType&lt;/th&gt;
       &lt;th&gt;Chem_Name&lt;/th&gt;
     &lt;/tr&gt;
   &lt;cfoutput query="BSAFbyOrganism"&gt;
     &lt;tr&gt;
       &lt;td&gt;#ID#&lt;/td&gt;
       &lt;td&gt;#StudyType#&lt;/td&gt;
       &lt;td&gt;#Chem_Name#&lt;/td&gt;
     &lt;/tr&gt;                  
   &lt;/cfoutput&gt;
  &lt;/table&gt;
  
  &lt;cfset q= BSAFbyOrganism&gt;
      &lt;cfset filename = expandPath("./myexcel.xls")&gt;
      &lt;cfspreadsheet action="write" query="BSAFbyOrganism" filename="#filename#" overwrite="true"&gt;
  
      &lt;!--- Make a spreadsheet object ---&gt;
      &lt;cfset s = spreadsheetNew()&gt;
      &lt;!--- Add header row ---&gt;
      &lt;cfset spreadsheetAddRow(s, "ID,StudyType,Chem_Name")&gt;
      &lt;!--- format header ---&gt;
      &lt;cfset spreadsheetFormatRow(s,
          {
              bold=true,
              fgcolor="lemon_chiffon",
              fontsize=14
          },
      1)&gt;
      &lt;!--- Add query ---&gt;
      &lt;cfset spreadsheetAddRows(s, q)&gt;
      &lt;cfset spreadsheetWrite(s, filename, true)&gt;
      &lt;cfheader name="content-disposition" value="attachment; filename=myexcel.xls"&gt;
  &lt;cfcontent type="application/msexcel" variable="#spreadsheetReadBinary(s)#" reset="true"&gt;
  </code></pre>