php不用COM生成excel文件

發表于:2007-07-14來源:作者:點擊數: 標簽:
用 php 生成excel文件 ? header(Content-type:application/vnd.ms-excel); header(Content-Disposition:filename=test.xls); echo test1\t; echo test2\t\n; echo test1\t; echo test2\t\n; echo test1\t; echo test2\t\n; echo test1\t; echo test2\t\n; ec
php生成excel文件  

<?
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls");
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
echo "test1\t";
echo "test2\t\n";
?>
  在php環境運行上面的代碼,大家就可以看到瀏覽器詢問用戶是否下載excel文檔,點擊保存,硬盤上就多了一個excel的文件,使用excel打開就會看到最終的結果,怎么樣不錯吧。
  其實在做真正的應用的時候,大家可以將數據從數據庫中取出,然后按照每一列數據結束后加\t,每一行數據結束后加\n的方法echo出來,在php的開頭用header("Content-type:application/vnd.ms-excel");表示輸出的是excel文件,用header("Content-Disposition:filename=test.xls");表示輸出的文件名為text.xls。這樣就ok了。



  我們更可以修改header讓他輸出更多格式的文件,這樣php在處理各種類型文件方面就更加方便了.

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97