<!--- Retrieve information about films --->
<CFQUERY DATASOURCE="ows" NAME="GetFilms">
  SELECT MovieTitle, AmountBudgeted
  FROM Films
  ORDER BY MovieTitle
</CFQUERY>

<!--- Set the content-type so Excel is invoked --->
<CFCONTENT TYPE="application/msexcel">

<!--- Suggest default filename for spreadsheet --->
<CFHEADER NAME="Content-Disposition" VALUE="filename=FilmBudgets.xls">

<!--- Include "XML Namespace" information to --->
<!--- allow using Excel "extensions" to HTML --->
<html 
  xmlns:o="urn:schemas-microsoft-com:office:office"
  xmlns:x="urn:schemas-microsoft-com:office:excel"
  xmlns="http://www.w3.org/TR/REC-html40">
<head><title>Film Budgets</title></head>


<body>

<style TYPE="text/css">
  .rowHeads {
    color:white;
    background:blue; 
  }
  .titleCol {
    width:400px;
    font-style:italic;
    font-family:verdana;
  }
  .priceCol {
    width:170px;
    font-family:verdana;
    color:red;
    mso-number-format:"\0022$\0022\#\,\#\#0\.00"
  };
</style>


<!--- Output ordinary HTML table, which will --->
<!--- be displayed by Excel as a spreadsheet --->
<table>
  <!--- Top row --->
  <tr>
    <th class="rowHeads">Movie Title</th>
    <th class="rowHeads">Amount Budgeted</th>
  </tr>
  
  <!--- Data rows --->
  <CFOUTPUT QUERY="GetFilms">
    <tr>
      <td class="titleCol">#MovieTitle#</td>
      <td class="priceCol">#AmountBudgeted#</td>
    </tr>
  </CFOUTPUT>
  
  <!--- Last row, with "total" formula --->
  <CFSET FirstPriceCell = "B2">
  <CFSET LastPriceCell  = "B" & GetFilms.RecordCount + 1>
  <CFSET TotalFormula   = "SUM(#FirstPriceCell#:#LastPriceCell#)">
  <CFOUTPUT>
    <tr>
      <td 
        class="titleCol" 
        style="font-weight:bold;background:yellow">Total:</td>
      <td 
        class="priceCol"  
        style="font-weight:bold;background:yellow"
        x:fmla="=#TotalFormula#"></td>
    </tr>
  </CFOUTPUT>
</table>

</body>
</html>
