title: PHPExcel not working perfectly
body: <p>I use <code>PHPExcel</code> library from <a href="https://github.com/PHPOffice/PHPExcel" rel="nofollow noreferrer">here</a> to create an excel file extension <code>.xlsx</code> 
  for that i use <code>php</code> and <code>mysql</code> the data of this excel file is from <code>mysql</code> database.</p>
  
  <p>After i create the code i receive this message:</p>
  
  <blockquote>
    <p>Excel can't open the file because the file format or file extension is
    not valid. Verify that the file has not been corrupted and that the
    file extension matches the format of the file</p>
  </blockquote>
  
  <p>To solve this problem i use:</p>
  
  <pre><code>ob_start(); ob_end_clean();
  </code></pre>
  
  <p>After that i download the file and try to open the excel file i have this message:</p>
  
  <blockquote>
    <p>We found a problem with some content in your file.Do you want to us to
    try to recover as much as we can?if you trust the source of this
    workbook,click yes.</p>
  </blockquote>
  
  <p>When i click yes i have this message:</p>
  
  <blockquote>
    <p>Excel completed file level validation and repair. Some parts of this
    workbook may have been repaired or discarded.</p>
  </blockquote>
  
  <p>I click close the excel file open but inside this excel file i have some empty rows with my data.</p>
  
  <p>This is my code to download an excel file using <code>PHPExcel</code></p>
  
  <pre><code>ob_start();
  include("includes/connect.php");
  require_once'PHPExcel/Classes/PHPExcel.php';
  //Create PHPExcel object
  $excel=new PHPExcel();
  //selecting active sheet
  $excel-&gt;setActiveSheetIndex(0);
  $row=21;
  while($data=mysqli_fetch_object($query)){
  $excel-&gt;getActiveSheet()-&gt;setCellvalue('A'.$row,$data-&gt;db_maid)
      -&gt;setCellvalue('B'.$row,$data-&gt;db_date) 
      -&gt;setCellvalue('C'.$row,$data-&gt;db_client)
      -&gt;setCellvalue('D'.$row,$data-&gt;db_esid)
      -&gt;setCellvalue('E'.$row,$data-&gt;db_type)    
      -&gt;setCellvalue('F'.$row,$data-&gt;db_phone)
      -&gt;setCellvalue('G'.$row,$data-&gt;db_mobile) 
      -&gt;setCellvalue('H'.$row,$data-&gt;db_contactperson)
      -&gt;setCellvalue('I'.$row,$data-&gt;db_competetivecompany)
      -&gt;setCellvalue('J'.$row,$data-&gt;db_category)    
      -&gt;setCellvalue('K'.$row,$data-&gt;db_process)
      -&gt;setCellvalue('L'.$row,$data-&gt;db_status) 
      -&gt;setCellvalue('M'.$row,$data-&gt;db_rate) 
      -&gt;setCellvalue('N'.$row,$data-&gt;db_doc)
      -&gt;setCellvalue('O'.$row,$data-&gt;nextDate)
      -&gt;setCellvalue('P'.$row,$data-&gt;db_ndstatus)
      -&gt;setCellvalue('Q'.$row,$data-&gt;db_pnote) 
      -&gt;setCellvalue('R'.$row,$data-&gt;meetingStatus) 
      -&gt;setCellvalue('S'.$row,$data-&gt;db_ncam)    
      -&gt;setCellvalue('T'.$row,$data-&gt;medit)
      -&gt;setCellvalue('U'.$row,$data-&gt;name);
      //incriment the row
  $row++;    
  }
  //set column width
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('A')-&gt;setWidth(10);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('B')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('B')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('D')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('E')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('F')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('G')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('H')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('I')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('J')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('K')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('L')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('M')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('N')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('O')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('P')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('Q')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('R')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('S')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('T')-&gt;setWidth(20);
  $excel-&gt;getActiveSheet()-&gt;getColumnDimension('U')-&gt;setWidth(20);
  //make table headers
  $excel-&gt;getActiveSheet()
        -&gt;setCellValue('A1','List Of Marketing')
        -&gt;setCellValue('A3','#')
        -&gt;setCellValue('B3','Date')
        -&gt;setCellValue('C3','Client')
        -&gt;setCellValue('D3','ES')
        -&gt;setCellValue('E3','Type')
        -&gt;setCellValue('F3','Phone')
        -&gt;setCellValue('G3','Mobile')
        -&gt;setCellValue('H3','Contact Person')
        -&gt;setCellValue('I3','Competetive Company')
        -&gt;setCellValue('J3','Categoty')
        -&gt;setCellValue('K3','Process')
        -&gt;setCellValue('L3','Status')
        -&gt;setCellValue('M3','Rate')
        -&gt;setCellValue('N3','Date Of Calling')
        -&gt;setCellValue('O3','Next Date')
        -&gt;setCellValue('P3','Next Date Status')
        -&gt;setCellValue('K3','Phone Note')
        -&gt;setCellValue('R3','Meeting Status')
        -&gt;setCellValue('S3','Next Call After Meeting')
        -&gt;setCellValue('T3','Edit Date')
        -&gt;setCellValue('U3','Staff');
  //Margin The title
  $excel-&gt;getActiveSheet()-&gt;mergeCells('A1:U1');
  //aligning
  $excel-&gt;getActiveSheet()-&gt;getStyle('A1')-&gt;getAlignment()-&gt;setHorizontal('center');
  //styling
  $excel-&gt;getActiveSheet()-&gt;getStyle('A1')-&gt;applyFromArray(
  array(
        'font'=&gt;array(
            'size'=&gt;24,
        )
  )
  );
  $excel-&gt;getActiveSheet()-&gt;getStyle('A3:U3')-&gt;applyFromArray(
  array(
     'font'=&gt;array(
         'bold'=&gt;true
     ),
      'borders'=&gt;array(
          'allborders'=&gt;array(
              'style'=&gt;PHPExcel_Style_Border::BORDER_THIN
          )
      )
  )
  );
  //give border to data
  $excel-&gt;getActiveSheet()-&gt;getStyle('A4:U'.($row-1))-&gt;applyFromArray(
  array(
      'borders'=&gt;array(
          'outline'=&gt;array(
              'style'=&gt;PHPExcel_Style_Border::BORDER_THIN
          ),
          'vertical'=&gt;array(
              'style'=&gt;PHPExcel_Style_Border::BORDER_THIN
          )
      )
  )
  );
  //write the result to a file
  $file=PHPExcel_IOFactory::createWriter($excel,'Excel2007');
  header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
  header('Content-Disposition: attachment; filename="marketing.xlsx"');
  header('Cache-Control:max-age=0');
  ob_end_clean();
  
  //output to php output instead of filename
  $file-&gt;save('php://output');
  </code></pre>
  
  <p>My question is How to solve this problem i don't want this message appear also i don't want to have an empty rows in my excel also <code>ob_end_clean()</code> is a real solution for the first message because i saw a tutorial on the internet and his code work correctly without using the <code>ob_end_clean()</code> or the <code>ob_start()</code>?</p>