分享

php?导出excel类

 航风个人图书馆 2011-09-30
php 导出excel类(2011-09-08 11:25:08)
标签:

php

excel

导出类

it

分类: php
详细使用方法,请进入http://www./?p=14查看
<?php
class Excel {
var $inEncode; //一般是页面编码
var $outEncode; //一般是Excel文件的编码
public function __construct(){
}
public function setEncode($incode,$outcode){
$this->inEncode=$incode;
$this->outEncode=$outcode;
}
public function setTitle($titlearr){
$title="";
foreach($titlearr as $v){
if($this->inEncode!=$this->outEncode){
$title.=iconv($this->inEncode,$this->outEncode,$v)."\t";
}
else{
$title.=$v."\t";
}
}
$title.="\n";
return $title;
}
public function setRow($array){
$content="";
foreach($array as $k => $v){
foreach($v as $vs){
if($this->inEncode!=$this->outEncode){
$content.=iconv($this->inEncode,$this->outEncode,$vs)."\t";
}
else{
$content.=$vs."\t";
}
}
$content.="\n";
}
return $content;
}
public function getExcel($titlearr,$array,$filename=''){
if($filename==''){
$filename=date("Y-m-d");
}
$title=$this->setTitle($titlearr);
$content=$this->setRow($array);
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$filename.".xls");
echo $title;
echo $content;
}
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约