百度空间 | 百度首页 
 
查看文章
 
PHP生成excle
2009-04-11 21:32
用php生成excel文件
PHP代码:
  1. <?
  2.    header("Content-type:application/vnd.ms-excel");
  3.    header("Content-Disposition:filename=test.xls");
  4.    echo "test1t";
  5.    echo "test2tn";
  6.    echo "test1t";
  7.    echo "test2tn";
  8.    echo "test1t";
  9.    echo "test2tn";
  10.    echo "test1t";
  11.    echo "test2tn";
  12.    echo "test1t";
  13.    echo "test2tn";
  14.    echo "test1t";
  15.    echo "test2tn";
  16. ?>

在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在处理各种类型

文件方面就更加方便了。

类别:网络程序 | 添加到搜藏 | 浏览() | 评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
验证码: 请点击后输入四位验证码,字母不区分大小写
      

     

©2009 Baidu