php导入到excel文件,且支持utf8和gbk两种编码。
php导入到excel乱码,原因在于utf8编码在xp系统不支持所有utf8编码,做一下转码就好了。
1,php导入excel文件,utf-8编码版。
复制代码 代码示例:
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
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-Disposition: attachment;filename=11.xls ");
header("Content-Transfer-Encoding: binary ");
?>
$filename="php导入到excel-utf-8编码";
$filename=iconv("utf-8", "gb2312", $filename);
echo $filename;
?>
2,php导入excel文件,gbk编码版。
复制代码 代码示例:
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
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-Disposition: attachment;filename=11.xls ");
header("Content-Transfer-Encoding: binary ");
?>
$filename="php导入到excel-utf-8编码";
echo $filename;
?>
说明:
在访问网页内容时, 会下载内容到excel文件中,如果需要表格效果,则在页面中用table实现即可。