文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>用php生成excel文件

用php生成excel文件

时间:2007-06-10  来源:sdqdgaopeng


PHP代码:


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

      
header
("Content-Disposition:filename=test.xls");

      
echo
"test1t";

      
echo
"test2tn";

      
echo
"test1t";

      
echo
"test2tn";

      
echo
"test1t";

      
echo
"test2tn";

      
echo
"test1t";

      
echo
"test2tn";

      
echo
"test1t";

      
echo
"test2tn";

      
echo
"test1t";

      
echo
"test2tn";

?>
在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在处理各种类型
文件方面就更加方便了。


相关阅读 更多 +
排行榜 更多 +
合合合军团

合合合军团

策略塔防 下载
街头滑板

街头滑板

体育竞技 下载
武者生存

武者生存

体育竞技 下载