php 导出excel类(2011-09-08 11:25:08)
详细使用方法,请进入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
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;
}
}
|
|