title: PHPExcel adding html to xls
body: <p>I have a page that creates an xls file with PHPExcel on post, which works fine, the file download pops up and everything is golden, but when i try to open the file i get an error saying excel cannot open the file. I checked all the data going in and everything was fine, so i figured it had to be something with the file.</p>
  
  <p>I opened the downloaded xls in notepad++, and sure enough, there was html at the top of the file, the same html for the page, up to where the content was called and the php checking the post ran. As soon as i deleted that it opened up just fine, still missing a few fields, but I'd like to make it actually viewable before i worry about that.</p>
  
  <p>Here's my code for creating the xls</p>
  
  <pre><code>global $__CMS_CONN__;
  error_reporting(E_ALL);
  $listmem = $_SESSION['listmem'];
  $evtdate1 = date('Y-m-d', strtotime('-1 year', strtotime(date('Y-m-d'))));
  $evtdate2 = date('Y-m-d');
  require_once('/web/content/wolf/plugins/Classes/PHPExcel.php');
  $sql = "SELECT Count(*) AS number FROM (SELECT DISTINCT event_timestamp FROM membership_attendance_log WHERE event_timestamp &gt;= '".$evtdate1."' AND event_timestamp &lt;= '".$evtdate2."') as numevents";
  $evtcount = $__CMS_CONN__-&gt;prepare($sql);
  $evtcount-&gt;execute();
  $count = $evtcount-&gt;fetchAll(PDO::FETCH_ASSOC);
  $objPHPExcel = new PHPExcel();
  $objPHPExcel-&gt;getActiveSheet()-&gt;mergeCells('A1:C1');
  $objPHPExcel-&gt;setActiveSheetIndex(0)
              -&gt;setCellValue('A1', 'Date Range: '.$evtdate1." to ".$evtdate2)
              -&gt;setCellValue('D1', 'Total number of events: '.$count['number'])
              -&gt;setCellValue('A2', 'Member')
              -&gt;setCellValue('B2', 'Missed Meetings')
              -&gt;setCellValue('C2', 'Attendance')
              -&gt;setCellValue('D2', 'Business Name')
              -&gt;setCellValue('E2', 'Title')
              -&gt;setCellValue('F2', 'Phone')
              -&gt;setCellValue('G2', 'Email');
  $objPHPExcel-&gt;getActiveSheet()-&gt;getStyle('A1:H1')-&gt;getFont()-&gt;setBold(true);
  $i = 3;
  foreach($listmem as $row)
  {
      $qry = "SELECT Count(membership_individual_id) AS attendance FROM membership_attendance_log WHERE membership_individual_id=".$row['id']." AND event_timestamp &gt;= '".$evtdate1."' AND event_timestamp &lt;= '".$evtdate2."'";
      $stmt = $__CMS_CONN__-&gt;prepare($qry);
      $stmt-&gt;execute();
      $attendance = $stmt-&gt;fetchAll(PDO::FETCH_ASSOC);
  
      $objPHPExcel-&gt;setActiveSheetIndex(0)
                  -&gt;setCellValue('A'.$i, $row['first_name']." ".$row['last_name'])
                  -&gt;setCellValue('B'.$i, $attendance['attendance'])
                  -&gt;setCellValue('C'.$i, floor($attendance['attendance'] / $count['number']))
                  -&gt;setCellValue('D'.$i, $row['business_name'])
                  -&gt;setCellValue('E'.$i, $row['title'])
                  -&gt;setCellValue('F'.$i, $row['business_phone'])
                  -&gt;setCellValue('G'.$i, $row['email']);
      $i++;
  }
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('A')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('B')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('C')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('D')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('E')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('F')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('G')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;getColumnDimension('H')-&gt;setAutoSize(true);
  $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('Report');
  $objPHPExcel-&gt;setActiveSheetIndex(0);
  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  header('Content-Disposition: attachment;filename="Report-'.date("mdY").'.xlsx"');
  header('Cache-Control: max-age=0');
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter-&gt;save('php://output');
  exit;
  </code></pre>
  
  <p>This is on a site using wolfCMS, just fyi. I tried pulling it out of the file and just having it post to a seperate php file but i still got the same thing.</p>