title: PHPExcel export HTML table to xlsx
body: <p>I need to <strong>export HTML table</strong> with data from database to <strong>xlsx file</strong> as easily as possible.</p>
  
  <p>I've tried <code>PHPExcel</code> and some JS plugins, but <strong>unsuccessfully</strong>. </p>
  
  <p>Is there any new solution? </p>
  
  <p>Everything I found was almost 10 years old. </p>
  
  <p>This is what I created:</p>
  
  <p>My HTML form:</p>
  
  <pre><code>&lt;form action="download.php"&gt;
      &lt;input type="submit" value="Export" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>My PHPExcel code (file: download.php):</p>
  
  <pre><code>&lt;?php
  
  require_once "../Classes/PHPExcel.php";
  
  $objPHPExcel = new PHPExcel();
  $objPHPExcel-&gt;getActiveSheet()-&gt;setCellValue('A1', 'hello world!');
  $objPHPExcel-&gt;getActiveSheet()-&gt;setTitle('Chesse1');
  
  header('Content-Type: application/vnd.ms-excel');
  header('Content-Disposition: attachment;filename="helloworld.xlsx"');
  header('Cache-Control: max-age=0');
  
  $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
  $objWriter-&gt;save('php://output');
  
  ?&gt;
  </code></pre>
  
  <p>When I click the button, it downloads the file, but I can't open it, because of <strong>"wrong format"</strong>.</p>
  
  <p>I also tried this video tutorial:
  <a href="https://www.youtube.com/watch?v=4dc3a4isHNE&amp;t=" rel="nofollow noreferrer">https://www.youtube.com/watch?v=4dc3a4isHNE&amp;t</a></p>
  
  <p>Exporting Excel file worked but another problem appeared.</p>
  
  <p>The problem I had was <strong>wrong charset</strong>.
  I need to use characters like: <strong>ě,š,č,ř,ž,ý,á,í</strong> etc. and these characters were totally messed up.</p>