php不使用插件导出excel的简单方法
这篇文章主要介绍了php不使用插件导出excel的简单方法,首先获取需要导出的数据的数组,数组的格式在下面。之后就是定义文件名称和需要导出的excel的样式,最后
复制代码 代码如下:
$filename=date("Y年m月d日")."数据信息统计结果.xls"; //文件名
$ua = $_SERVER["HTTP_USER_AGENT"]; //中文文件名不乱码
if (preg_match("/MSIE/", $ua)) {
$filename=urlencode($filename);
} else if (preg_match("/Firefox/", $ua)) {
$filename=$filename;
} else {
$filename=urlencode($filename);
}
header("Content-type:application/vnd.ms-excel"); //输出excel头
header("Content-Disposition:filename=".$filename);
$n = iconv('utf-8', 'gbk', '11'); //设置excel表格列
$t = iconv('utf-8', 'gbk', '22');
$k = iconv('utf-8', 'gbk', '33');
$s = iconv('utf-8', 'gbk', '44');
$r= iconv('utf-8', 'gbk', '55');
$a= iconv('utf-8', 'gbk', '66');
echo "{$n}\t";
echo "{$t}\t";
echo "{$k}\t";
echo "{$s}\t";
echo "{$r}\t";
echo "{$a}\t\n";
foreach($a as $kk=>$pp){ //对每列些数据
foreach($pp['child'] as $k=>$p){
echo iconv("utf-8", "gbk//IGNORE", $pp['u']."\t");
echo iconv("utf-8", "gbk//IGNORE", $p['u']."\t");
echo iconv("utf-8", "gbk//IGNORE", $p['s']."\t");
echo iconv("utf-8", "gbk//IGNORE", $p['t']."\t");
echo iconv("utf-8", "gbk//IGNORE", $p['c']."\t");
echo iconv("utf-8", "gbk//IGNORE", $p['t']."\t\n");
}
}
数组格式为
复制代码 代码如下:
Array
(
[0] => Array
(
[unitid] => 1234
[u] => aaa
[fid] => 1000
[shengid] => 1000
[shiid] => 0
[xianid] => 0
[rid] => 2
[orders] => 50
[sys_createuid] => 1
[sys_createtime] => 1383556976
[sys_updateuid] => 1
[sys_updatetime] => 1389853763
[child] => Array
(
[0] => Array
(
[unitid] => 1035
[u] => bbb
[fid] => 1000
[shengid] => 1000
[shiid] => 0
[xianid] => 0
[rid] => 2
[orders] => 50
[sys_createuid] => 1
[sys_createtime] => 1383556976
[sys_updateuid] => 1
[sys_updatetime] => 1389853763
[funitname] =>
[s] => 6
[t] => 1
[c] => 1
[t] => 2
)
[4] => Array
(
[u] => 合计
[s] => 8
[t] => 1
[c] => 3
[t] => 3
))))
上一篇: VS2005中,access对只读目录的属性判断不准确
下一篇: 机房收费系统系列四:上下机
推荐阅读
-
php不使用插件导出excel的简单方法
-
php中导出数据到excel时数字变为科学计数的解决方法
-
php把数据表导出为Excel表的最简单、最快的方法(不用插件)
-
PHP导出EXCEL快速开发指南--PHPEXCEL的使用详解
-
php使用指定编码导出mysql数据到csv文件的方法
-
PHP使用json_encode函数时不转义中文的解决方法,
-
jquery+php实现导出datatables插件数据到excel的方法,jquerydatatables_PHP教程
-
thinkPHP导出csv文件及用表格输出excel的方法_php实例
-
基于php中使用excel的简单介绍_PHP教程
-
PHP生成Excel文件的简单方法(附代码)