在下載 AppServ 過程時發現了Example PHP export to XLS file format ,但用了一

段時間還是沒辦法正常的產生 xls 格式的檔案,在測試過程發生了

cannot modify header information

PHP 錯誤,將 php.ini 中 output_buffering 改成 On 後重啟 Apache 後就可正常執行,但

還是找了一個簡單產生Excel檔案的方法,產生的方式是簡單的產生一個CSV格式的檔案。

程式碼:

<?php
    
      $filename ="test.xls";
 
      $contents = "編號 \t 姓名 \t 職務 \t \n";
      $contents = $contents." 1 \t 小明 \t 董事長 \t \n";
      $contents = $contents." 2 \t 小華 \t 總經理 \t \n";
      
      header('Content-type: application/ms-excel');
      header('Content-Disposition: attachment; filename='.$filename);
      echo $contents;
    
?>

 

執行結果:

 

2010-03-31_135203

 

How to php export to excel

arrow
arrow
    全站熱搜

    iammic 發表在 痞客邦 留言(0) 人氣()