Laravel:导出 CSV 时出现 UTF-8 问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38929492/
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
Laravel : UTF-8 issue while exporting CSV
提问by Hola
While trying to export data form database I saw some garbage value instead of showing the actual data which is UTF-8 character. I used Excel for opening the csv and I used Maatwebsite/Laravel-Excelpackage for exporting the csv.
在尝试从数据库导出数据时,我看到了一些垃圾值,而不是显示 UTF-8 字符的实际数据。我使用 Excel 打开 csv,并使用Maatwebsite/Laravel-Excel包导出 csv。
Here is my controller :
这是我的控制器:
public function downloadExcel($type)
{
$data = Item::get()->toArray();
return Excel::create('solutionstuff_example', function($excel) use ($data) {
header('Content-Encoding: UTF-8');
header('Content-type: text/csv; charset=UTF-8');
header('Content-Disposition: attachment; filename=solutionstuff_example.csv');
$excel->sheet('mySheet', function($sheet) use ($data)
{
$sheet->fromArray($data);
});
})->download($type);
}
Here is snap of it:
这是它的快照:
If anybody face the problem and know how to fix it.Hope you'll help me to solve it. Thanks
如果有人遇到这个问题并知道如何解决它。希望你能帮助我解决它。谢谢