How to download a Excel sheet from the PHP code
<p>I have written the code for getting data from the database and store it in the Excel sheet.I want to download the excel file only. But the following code give the PHP file output as my excel file content. But I need to download the Excel file which is created in the PHP file. </p>

<pre><code> &lt;?php 
 $start_date="01/06/2010";
          $end_date="23/06/2010";
          $filename=$user.".xls";

          require 'DB.php' ; 
          include 'Spreadsheet/Excel/Writer.php'; 
          $excel = new Spreadsheet_Excel_Writer($filename);
          $format_bold =&amp; $excel-&gt;addFormat();
          $format_bold-&gt;setBold();
          $format_bold-&gt;setColor('red'); 
          $sheet= $excel-&gt;addWorksheet('Class I');
          $sheet-&gt;write(0, 0, "Field Name",$format_bold);
          $sheet-&gt;write(0, 1,"Field Name", $format_bold);
          $sheet-&gt;write(0, 2, "Filed Name",$format_bold); 
          $sheet-&gt;write(0, 3,"Filed name", $format_bold);
          $db = DB::connect( connect query);
          $q=$db-&gt;getAll("select * from table_name"); 
          $rowCount=1;
         foreach ($q as $row)
         {
                foreach ($row as $key =&gt; $value) 
                 {
                    $sheet-&gt;write($rowCount, $key, $value);
                 }
      $rowCount++;
        }
header('Pragma: no-cache');
header('Expires: 0');
header("Content-type: application/x-msexcel");
header("Content-Type: application/force-download");
header('Content-Disposition: attachment; filename="'$filename'"');
?&gt; 
</code></pre>
