title: Why am I getting encoding problems with phpspreadsheet?
body: <p>I'm trying to get a <a href="https://github.com/PHPOffice/PhpSpreadsheet" rel="nofollow noreferrer">phpspreadsheet</a> hello world code working... Just copied from their examples (that work properly) to a new php. But by navigating it, a corrupted xls files gets created. I think it has something to do with encoding, but my document is pure utf-8 (sublime text), and the code is copied from their working example:</p>
  
  <pre><code> &lt;?php
    require_once 'vendor/autoload.php';
  
    use PhpOffice\PhpSpreadsheet\Helper\Sample;
    use PhpOffice\PhpSpreadsheet\IOFactory;
    use PhpOffice\PhpSpreadsheet\Spreadsheet;
  
    require_once 'vendor/phpoffice/phpspreadsheet/src/Bootstrap.php';
  
    $helper = new Sample();
    if ($helper-&gt;isCli()) {
        $helper-&gt;log('This example should only be run from a Web Browser' . PHP_EOL);
  
        return;
    }
  
    // Create new Spreadsheet object
    $spreadsheet = new Spreadsheet();
  
    // Set document properties
    $spreadsheet-&gt;getProperties()-&gt;setCreator('Maarten Balliauw')
        -&gt;setLastModifiedBy('Maarten Balliauw')
        -&gt;setTitle('Office 2007 XLSX Test Document')
        -&gt;setSubject('Office 2007 XLSX Test Document')
        -&gt;setDescription('Test document for Office 2007 XLSX, generated using PHP classes.')
        -&gt;setKeywords('office 2007 openxml php')
        -&gt;setCategory('Test result file');
  
    // Add some data
    $spreadsheet-&gt;setActiveSheetIndex(0)
        -&gt;setCellValue('A1', 'Hello')
        -&gt;setCellValue('B2', 'world!')
        -&gt;setCellValue('C1', 'Hello')
        -&gt;setCellValue('D2', 'world!');
  
    // Miscellaneous glyphs, UTF-8
    $spreadsheet-&gt;setActiveSheetIndex(0)
        -&gt;setCellValue('A4', 'Miscellaneous glyphs')
        -&gt;setCellValue('A5', 'éàèùâêîôûëïüÿäöüç');
  
    // Rename worksheet
    $spreadsheet-&gt;getActiveSheet()-&gt;setTitle('Simple');
  
    // Set active sheet index to the first sheet, so Excel opens this as the first sheet
    $spreadsheet-&gt;setActiveSheetIndex(0);
  
    // Redirect output to a client’s web browser (Xls)
    header('Content-Type: application/vnd.ms-excel');
    header('Content-Disposition: attachment;filename="01simple.xls"');
    header('Cache-Control: max-age=0');
    // If you're serving to IE 9, then the following may be needed
    header('Cache-Control: max-age=1');
  
    // If you're serving to IE over SSL, then the following may be needed
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
    header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
    header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
    header('Pragma: public'); // HTTP/1.0
  
    $writer = IOFactory::createWriter($spreadsheet, 'Xls');
    $writer-&gt;save('php://output');
    exit;
  </code></pre>
  
  <p>What I get is this:</p>
  
  <p><a href="https://i.stack.imgur.com/9Lbpc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9Lbpc.png" alt="enter image description here"></a></p>
  
  <p>So what? Why?</p>