问题
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
回答1:
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:
来源:https://stackoverflow.com/questions/38929492/laravel-utf-8-issue-while-exporting-csv