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方式导出不会出现莫名的乱码现象
,下面我们就来说一说关于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方式导出不会出现莫名的乱码现象
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com