<?php
class Excel {
var $inEncode;
var $outEncode;
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 );
$filename=iconv("UTF-8","GB2312",$filename);
header ( "Content-type:application/vnd.ms-exce8 charset=UTF-8" );
header ( "Content-Disposition:attachment; filename=" . $filename . ".xls" );
echo $title;
echo $content;
}
}

$excel = new Excel ();
// 设置编码:
$excel->setEncode ( "utf-8", "gb2312" ); // 如果不转码,参数写一样即可,例如$excel->setEncode("utf-8","utf-8");
// 设置标题栏
$titlearr = array (
"a",
"b",
"c",
"d"
);
// 设置内容栏
$contentarr = array (
1 => array (
"中国",
"ac",
"ad",
"ae"
),
2 => array (
"abc",
"acc",
"adc",
"aec"
),
3 => array (
"abd",
"acd",
"add",
"aed"
),
4 => array (
"abe",
"ace",
"ade",
"aee"
)
);
$excel->getExcel ( $titlearr, $contentarr, "导出excel" );

?>

最新文章

  1. js 基本类型与引用类型的区别
  2. dictionaryWithContentsOfFile:方法
  3. 解决eclipse使用Search弹出错误问题
  4. oracle 语句创建表空间、用户、授权
  5. IconVault – 创建自定义图标字体的神器推荐
  6. 构建seajs业务模块之grunt VS spm build
  7. ASP.Net 上传进度条的实现方法
  8. myeclipse 10的破解以及运行run.bat错误或者双击立即消失的问题
  9. layoutSubviews -- setNeedsLayout -- layoutIfNeeded -- 区别
  10. 捉虫记2:windows程序句柄泄露的上下文环境
  11. cf602A Two Bases
  12. SqlServer sysobjects_table
  13. 如何从本地把项目上传到github&amp;&amp;如何把github项目通过clone复制下来
  14. Python协程爬取妹子图(内有福利,你懂得~)
  15. Linux动态频率调节系统CPUFreq之二:核心(core)架构与API
  16. springboot springmvc拦截器 拦截POST、PUT、DELETE请求参数和响应数据,并记录操作日志
  17. SVG 学习&lt;六&gt; SVG的transform
  18. 探索Javascript异步编程
  19. mysql 权限管理 revoke 回收权限 命令
  20. Sql Server 数据库扩展

热门文章

  1. Java爬虫(二)
  2. C#开发微信公众平台开发-微信海报介绍和开发流程
  3. 2017 ACM ICPC Asia Regional - Daejeon
  4. caffe Python API 之Solver定义
  5. count(*)与count(1)、count(&#39;xxx&#39;)等在使用语法方面的区别
  6. ActiveMQ-Network of brokers集群模式
  7. Windows Phone 8/Windows 8 启动第三方应用程序并传递参数
  8. Python+Selenium 自动化实现实例-模块化调用
  9. Python+Selenium 自动化实现实例-实现文件下载
  10. centos 下tomcat 自动启动