六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 900|回复: 0

php 导出excel类

[复制链接]
 楼主| 发表于 2012-9-7 12:59:11 | 显示全部楼层 |阅读模式
详细使用方法,请进入http://www.cnlamp.org/?p=14查看
  1. <?php
  2. class Excel {
  3. var $inEncode; //一般是页面编码
  4. var $outEncode; //一般是Excel文件的编码
  5. public function __construct(){
  6. }
  7. public function setEncode($incode,$outcode){
  8. $this->inEncode=$incode;
  9. $this->outEncode=$outcode;
  10. }
  11. public function setTitle($titlearr){
  12. $title="";
  13. foreach($titlearr as $v){
  14. if($this->inEncode!=$this->outEncode){
  15. $title.=iconv($this->inEncode,$this->outEncode,$v)."\t";
  16. }
  17. else{
  18. $title.=$v."\t";
  19. }
  20. }
  21. $title.="\n";
  22. return $title;
  23. }
  24. public function setRow($array){
  25. $content="";
  26. foreach($array as $k => $v){
  27. foreach($v as $vs){
  28. if($this->inEncode!=$this->outEncode){
  29. $content.=iconv($this->inEncode,$this->outEncode,$vs)."\t";
  30. }
  31. else{
  32. $content.=$vs."\t";
  33. }
  34. }
  35. $content.="\n";
  36. }
  37. return $content;
  38. }
  39. public function getExcel($titlearr,$array,$filename=''){
  40. if($filename==''){
  41. $filename=date("Y-m-d");
  42. }
  43. $title=$this->setTitle($titlearr);
  44. $content=$this->setRow($array);
  45. header("Content-type:application/vnd.ms-excel");
  46. header("Content-Disposition:filename=".$filename.".xls");
  47. echo $title;
  48. echo $content;
  49. }
  50. }

复制代码
该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表