php PHPEXCEL 设置 UTF-8 编码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16301384/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHPEXCEL set UTF-8 encode
提问by user2287965
I have headers:
我有标题:
header('Content-Type: text/html; charset=UTF-8');
header("Content-type: application/octetstream");
header('Content-Disposition: attachment; filename="export.csv"');
but decoding not work correct if I have word in database "Pagrindin?"
in excel show "Pagrindin?"
, what is wrong with my headers ?
但是如果我"Pagrindin?"
在 excel show中的数据库中 有单词,则解码不正确"Pagrindin?"
,我的标题有什么问题?
采纳答案by M8R-1jmw5r
What is wrong with my headers ?
我的标题有什么问题?
Nothing, your headers are looking fine.
没什么,你的标题看起来不错。
What is wrong with Excel?
Excel 有什么问题?
The user who opens the file in Excel needs to tell Excel that the file is in UTF-8 encoding. Direct that user to contact the vendor of the software it uses for her/his support options.
在 Excel 中打开文件的用户需要告诉 Excel 该文件采用 UTF-8 编码。指导该用户联系其用于她/他的支持选项的软件供应商。
Users of LibreOfficeor a derivate of it do not have that problem btw., so one solution is to tell those to install a suite of such, open the CSV file and save it as Excel file for example.
顺便说一句,LibreOffice或其衍生版本的用户没有这个问题,所以一个解决方案是告诉他们安装一套这样的套件,例如打开 CSV 文件并将其另存为 Excel 文件。
Or you directly create the Excel file on your server.
或者您直接在服务器上创建 Excel 文件。
回答by PedroSaiz
Maybe if you change the format text encoding of your .php file when you save it, to Unicode (UTF-8). It works for me.
也许如果您在保存 .php 文件时将其格式文本编码更改为 Unicode (UTF-8)。这个对我有用。
Hope it helps.
希望能帮助到你。
回答by Alireza S.T.
try this:
尝试这个:
header('Content-Transfer-Encoding: binary');
header("Content-Type: application/octet-stream");
header("Content-Transfer-Encoding: binary");
header('Expires: '.gmdate('D, d M Y H:i:s').' GMT');
header('Content-Disposition: attachment; filename = "Export '.date("Y-m-d").'.xls"');
header('Pragma: no-cache');
//these characters will make correct encoding to excel
echo chr(255).chr(254).iconv("UTF-8", "UTF-16LE//IGNORE", $out);