PHP到Excel文件:列显示公式为字符串

I have a problem with some column of my excel file that I export from php. Others column is working fine with the formula but another two columns have problem

  1. A column with formula not execute the formula but show the formula as a string, the formula will be working/execute normally when user click on the column and the press Enter. It's no problem if just have a couple of row on the file that need to execute manually, if there's lot of rows then lot of work should be done.
  2. Another column have same problem but this only happen on the first six row, the rest of the row working normal.

I think this not problem with the formula, because the formula just working fine when I hit enter on the cell to execute manually.

Anyone know how to solved this?

Thanks in advanced.



Here is screen shoot of the column

enter image description here

Here is my code of header

header("Content-Type: application/vnd.ms-excel;");
date_default_timezone_set("Asia/Jakarta");
header("Content-Disposition: attachment; filename=Laporan_Absensi_".date("d-m-Y").date("_H-i"));

For the problem of point 1., here is the code how I set the column

<td style="vnd.ms-excel.numberformat:#,##0_) \Rp;" align="right"><?=$penalty?></td> 

For the problem of point 2., here is the code how I set the column

<td style="background-color:#99CCFF;vnd.ms-excel.numberformat:h:mm;" align="right"><?=$form?></td>

$penalty and $form is the variable where I store the formula

It would be something like this:

$result = mysql_query('SELECT * FROM `some_table`'); 
if (!$result) die('Couldn\'t fetch records'); 
$num_fields = mysql_num_fields($result); 
$headers = array(); 
for ($i = 0; $i < $num_fields; $i++) 
{     
   $headers[] = mysql_field_name($result , $i); 
} 
$fp = fopen('php://output', 'w'); 
if ($fp && $result) 
{     
   header('Content-Type: text/csv');
   header('Content-Disposition: attachment; filename="export.csv"');
   header('Pragma: no-cache');    
   header('Expires: 0');
   fputcsv($fp, $headers); 
   while ($row = mysql_fetch_row($result)) 
   {
      fputcsv($fp, array_values($row)); 
   }
die; 
}