php does not use plug ins to export excel in a simple way

  • 2021-01-25 07:19:37
  • OfStack


$filename=date("Y years m month d day ")." Data information statistical results .xls";     // The file name 
$ua = $_SERVER["HTTP_USER_AGENT"];        // Chinese file names are not messy 
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");   // The output excel head 
header("Content-Disposition:filename=".$filename);
$n = iconv('utf-8', 'gbk', '11');       // Set up the excel Your table column 
$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){          // For each column 
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");
}
}

The array format is


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


Related articles: