正常仅需将utf-8转为gbk即可,IE内核的如下处理,PHP代码如下:
//
$ua = $_SERVER['HTTP_USER_AGENT'];
$ua = strtolower($ua);
if(preg_match('/msie/', $ua) || preg_match('/edge/', $ua) || preg_match('/trident/', $ua)) { //判断是否为IE或Edge浏览器
$filename = str_replace('+', '%20', urlencode($filename)); //使用urlencode对文件名进行重新编码
}
//2、浏览器保存
ob_end_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); //告诉浏览器输出07Excel文件
//header('Content-Type:application/vnd.ms-excel');//告诉浏览器将要输出Excel03版本文件
header('Content-Disposition: attachment;filename=' . $filename . '.xlsx'); //告诉浏览器输出浏览器名称
header('Cache-Control: max-age=0'); //禁止缓存
header("Content-Transfer-Encoding:binary");
$PHPWriter->save("php://output");
网友评论