title: Create XLS file from MySQL database using PHP script
body: <p>I want to generate XLS files with a PHP script from a MySQL database. The big problem here is that when I open the new exported .xls file, I see the values OK (i.e. it is correctly formatted) but the colour of the field changed to white. However, I need the colour unchanged, as is by default in Excel.</p>
  
  <p>Here is the PHP script that I use to extract data <em>from my database</em>.</p>
  
  <pre><code> &lt;?php
              include 'connect.php';
              $result = mysql_query('SELECT * FROM projects2');
  
              ?&gt;
  
          &lt;center&gt;&lt;h1&gt;Lista valorilor din tabela&lt;/h1&gt;
          &lt;h2&gt;&lt;a href="lec_datepm.php?exporta_lista_clienti=1" title="Exporta lista clienti in Excell" target="_blank"&gt;Exporta lista Clienti&lt;/a&gt;&lt;/h2&gt;&lt;/center&gt;
  
          &lt;?php
              include_once 'tabel_clientipm.php';
          ?&gt;
  </code></pre>
  
  <p>The PHP file used to generate the XLS file is:</p>
  
  <pre><code>&lt;?php
      include 'connect.php';
      $result = mysql_query('SELECT * FROM projects2');
  
      if (isset($_GET['exporta_lista_clienti'])) {
      $filename = 'raportnou.xls';
  
      header("Content-type: application/ms-excel");
      header("Content-Disposition: attachment; filename=$filename");
  
      include_once 'tabel_clientipm.php';
  
      exit();
      }
  ?&gt;
  </code></pre>
  
  <p>I added the tabel_clientipm.php:</p>
  
  <pre><code>&lt;center&gt;
  &lt;table border="1"&gt;
      &lt;tr&gt;
          &lt;th&gt;surname&lt;/th&gt;
          &lt;th&gt;name&lt;/th&gt;
          &lt;th&gt;age&lt;/th&gt;
  
      &lt;/tr&gt;
      &lt;?php
          while ($client = mysql_fetch_assoc($result)) {
      ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?php echo $client['surname'];?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $client['name'];?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?php echo $client['age'];?&gt;&lt;/td&gt;
  
      &lt;/tr&gt;
      &lt;?php
          }
      ?&gt;
  &lt;/table&gt;
  &lt;/center&gt;
  </code></pre>