function downExcel($data)
{
$fileName = 'lottery' . date('YmdH') . '.xls';
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=" . $fileName);
header('Cache-Control: max-age=0');
$tab = "\t";
$br = "\n";
$head = "编号" . $tab . "奖品" . $tab . "姓名" . $tab . "电话" . $tab . "地址" . $tab . "中奖日期";
$head = iconv("UTF-8", "gb2312//IGNORE", $head);
//输出内容如下:
echo $head . $br;
foreach ($data as $key => $value) {
echo ($key 1) . $tab;
foreach ($value as $kk => $mn) {
if (in_array($kk, ['name', 'prize_name', 'address'])) {
$mn = iconv("UTF-8", "gbk//IGNORE", $mn);
$mn = str_replace("\n", "", $mn);
echo $mn . $tab;
} elseif ($kk == 'phone' || $kk == 'create_time') {
$mn = "=\"{$mn}\""; //原样输出需要处理
echo $mn . $tab;
}
}
echo $br;
}
exit;
}
使用这种html方式导出不会出现莫名的乱码现象
,下面我们就来说一说关于excel导出功能?我们一起去了解并探讨一下这个问题吧!
excel导出功能
function downExcel($data)
{
$fileName = 'lottery' . date('YmdH') . '.xls';
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:attachment;filename=" . $fileName);
header('Cache-Control: max-age=0');
$tab = "\t";
$br = "\n";
$head = "编号" . $tab . "奖品" . $tab . "姓名" . $tab . "电话" . $tab . "地址" . $tab . "中奖日期";
$head = iconv("UTF-8", "gb2312//IGNORE", $head);
//输出内容如下:
echo $head . $br;
foreach ($data as $key => $value) {
echo ($key 1) . $tab;
foreach ($value as $kk => $mn) {
if (in_array($kk, ['name', 'prize_name', 'address'])) {
$mn = iconv("UTF-8", "gbk//IGNORE", $mn);
$mn = str_replace("\n", "", $mn);
echo $mn . $tab;
} elseif ($kk == 'phone' || $kk == 'create_time') {
$mn = "=\"{$mn}\""; //原样输出需要处理
echo $mn . $tab;
}
}
echo $br;
}
exit;
}
使用这种html方式导出不会出现莫名的乱码现象