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導出功能?我們一起去了解并探讨一下這個問題吧!
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方式導出不會出現莫名的亂碼現象
更多精彩资讯请关注tft每日頭條,我们将持续为您更新最新资讯!