PHP 写入资料到EXCEL中

来源:互联网 发布:中国网络电视全球在线 编辑:程序博客网 时间:2024/06/05 21:00

 

<?php
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

header("Content-type:application/vnd.ms-excel");

header("Content-Disposition:filename=order.xls");
//
下面就可以处理一般的PHP文件一样处理,可以连接数据库,显示图象等操作,最后会显示在EXCEL文件中

?>
  在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了。

原创粉丝点击