Laravel:导出CSV时出现UTF-8问题 [英] Laravel : UTF-8 issue while exporting CSV

查看:951
本文介绍了Laravel:导出CSV时出现UTF-8问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试导出数据表单数据库时,我看到一些垃圾值,而不是显示UTF-8字符的实际数据。我使用Excel打开csv,我使用



如果有人面对问题,并知道如何解决它。希望你会帮助我解决它。
感谢

解决方案

我已解决问题:



我更改了值:
'use_bom'=> false

'use_bom'=> ; 中的 csv'部分中的 excel.php 文件。
祝你成功!



图片详细资料:




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-Excel package for exporting the 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

解决方案

I have solved the problem:

I changed the value: 'use_bom'=>false to 'use_bom'=>true

in the 'csv' part of excel.php file in config folder. I wish you success!

Image details:

这篇关于Laravel:导出CSV时出现UTF-8问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆