PHPEXCEL设置UTF-8编码


PHPEXCEL set UTF-8 encode

我有标题:

            header('Content-Type: text/html; charset=UTF-8');
            header("Content-type: application/octetstream");
            header('Content-Disposition: attachment; filename="export.csv"');

但解码不工作正确,如果我有字在数据库"Pagrindinė"在excel显示"PagrindinÄ",我的头有什么问题?

我的头有什么问题?

没什么,你的标题看起来很好。

Excel有什么问题?

在Excel中打开文件的用户需要告诉Excel该文件是UTF-8编码。指导该用户联系其使用的软件供应商,以获得其支持选项。

使用LibreOffice或其衍生版本的用户不会有这个问题。,所以一个解决方案是告诉他们安装一个这样的套件,例如打开CSV文件并将其保存为Excel文件。

或者直接在服务器上创建Excel文件

也许如果您在保存.php文件时更改格式文本编码为Unicode (UTF-8)。

希望能有所帮助。

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);