PHP导出Excel格式文件(xls)

PHP导出Excel格式文件(xls),比想像中要简单的多,只需给PHP文件加一个文件头,filename 就是导出的xls文件名,当你点击这个文件的URL时,就会提示你下载xls文件了

header("Content-Type: application/vnd.ms-execl");
header("Content-Disposition: attachment; filename=info.xls");
header("Pragma: no-cache");
header("Expires: 0");

以下是全部代码:

  1. <?php
  2. header("Content-Type: application/vnd.ms-execl");
  3. header("Content-Disposition: attachment; filename=info.xls");
  4. header("Pragma: no-cache");
  5. header("Expires: 0");
  6. require_once(dirname(__FILE__)."/../include/config_base.php");
  7. require_once(dirname(__FILE__)."/../dede/config.php");
  8. require_once(dirname(__FILE__)."/../include/pub_datalist.php");
  9. $dsql = new DedeSql(false);
  10.  
  11.  
  12. echo "订阅日期"."\t";
  13. echo "订阅内容"."\t";
  14. echo "姓名"."\t";
  15.  
  16.  
  17. $dsql->SetQuery("Select * from `TableName` order by `id` desc");
  18. $dsql->Execute();
  19. $i = 1;
  20.  
  21. while($row = $dsql->GetArray())
  22. {
  23.  
  24.  
  25.     echo $row['uTime']."\t";
  26.     echo $row['uCont']."\t";
  27.     echo $row['uName']."\t";
  28.    
  29.     $i++;
  30. }
  31. ?>

1 条评论

  1. maudo

    导出来好做,我现在正找读取的呢!!不好找,呵呵!!

发表评论

验证码: 验证码看不清发泄点这里

 

浏览最多的10篇日志

评论最多的10篇日志

随机显示的10篇日志