php,不用COM,生成excel文件

来源:互联网 发布:C语言roll程序 编辑:程序博客网 时间:2024/06/01 09:33
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
COM" target=_blank>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";
?>
  在COM" target=_blank>php环境运行上面的代码,大家就可以看到浏览器询问用户是否下载excel文档,点击保存,硬盘上就多了一个excel文件,使用excel打开就会看到最终的结果,怎么样不错吧。
  其实在做真正的应用的时候,大家可以将数据从数据库中取出,然后按照每一列数据结束后加/t,每一行数据结束后加/n的方法echo出来,在COM" target=_blank>php的开头用header("Content-type:application/vnd.ms-excel");表示输出的是excel文件,用header("Content-Disposition:filename=test.xls");表示输出的文件名为text.xls。这样就ok了。



  我们更可以修改header让他输出更多格式的文件,这样COM" target=_blank>php在处理各种类型文件方面就更加方便了.
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击