Exporting data from PHP to Excel format
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/3968973/how-can-i-write-data-into-an-excel-using-php">How can i write data into an excel using PHP</a>  </p>
</blockquote>



<p>I got a real problem here...</p>

<p>I tried to export my data through an excel file but i got this error. </p>

<p>This is the error message:</p>

<p>The file you are trying to open, 'library_record_011413-0117-13.xls', is in different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?</p>

<p>Here's my code:</p>

<pre><code>  $ext = "xls";
  $fileName = "library_record_".$fromdate."-".$todate.".".$ext;

  $contents = "DATE\tPROJECT NAME\tVERSION TYPE\tVERSION NUMBER\tAUTHOR\tCHECK-IN     TIME\tCHECK-OUT TIME\tNEW VERSION NO.\tREMARKS\tRECEIVED BY";
  $contents .= " \n";

  $array = $User-&gt;getLogsByDate($from, $to);

  foreach($array as $versions){
  $contents .= $versions['fld_date']."\t".$versions['fld_projectName']." \t".$versions['fld_versionName']."\t".$versions['fld_versionNo']."\t".$versions['fld_author']."\t".$versions['fld_checkInTime']."\t".$versions['fld_checkOutTime']."\t".$versions['fld_newVersionNo']."\t".$versions['fld_remarks']."\t".$versions['fld_receivedBy']."\t\n";
          }

  header('Content-Type: application/vnd.ms-excel');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Content-Disposition: attachment; filename='.$fileName);

  echo $contents;
</code></pre>

<p>Though i could open the excel file, but i can't get rid of this error. So everytime i open the file, the error would pop-up.</p>

<p>Thanks in advance.</p>
