Home >Backend Development >PHP Tutorial >A simple way to export excel in php without using a plug-in_PHP tutorial

A simple way to export excel in php without using a plug-in_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-13 10:37:03848browse

Copy code The code is as follows:

$filename=date("Y year m month d day")."Data information Statistical results.xls"; //File name
$ua = $_SERVER["HTTP_USER_AGENT"]; //Chinese file name is not garbled
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"); //Output excel header
header("Content-Disposition:filename=" .$filename);
$n = iconv('utf-8', 'gbk', '11'); //Set excel table columns
$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}tn";

   
foreach($a as $kk=>$pp){     //For each column of data
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']."tn");
}
}

The array format is

Copy code The code is as follows:

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] => ; Total
[s] => 8
[t] => 1
[c] => 3
[t] => 3
))))

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/736802.htmlTechArticleCopy the code as follows: $filename=date("Y year m month d day")."Data information statistics Result.xls"; //File name $ua = $_SERVER["HTTP_USER_AGENT"]; //Chinese file name is not garbled if (preg_match("...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn