Laravel-excel: UTF8 problem in CSV export

Created on 4 Aug 2014  ·  19Comments  ·  Source: Maatwebsite/Laravel-Excel

When I use "->export('xls')", the result is ok, but if I use "->export('csv')", the UTF8 charcters come with encode problem.
Exemple: Waister Guimarães,"[email protected]"

Most helpful comment

for who still get this problem, try edit config/excel.php : from 'use_bom' => false to 'use_bom' => true

All 19 comments

If it goes right with xls, than it could be an issue with the csv writer of PHPExcel. Did you check their issues and forum for this error?

Yes, I did check and foud questions, but just for import behaviour.
I attach two files, one in XLS and other in CSV, same generateds by this code (with ->download('xml') of course):

Excel::create('New file', function($excel) {
$excel->sheet('New sheet', function($sheet) {
$sheet->loadView('test');
});
})->download('csv');

Ah you are using a view. Try including <meta charset="UTF-8"> in the head of the view file, that should force the use of UTF-8.

Sorry, I forgot to attach files in hte last comment.
I used the view for testing only. Even with the mega tag not work too.

can any one tell me step by step in exporting laravel excel

On Thu, Aug 7, 2014 at 2:07 AM, Waister Nunes [email protected]
wrote:

Sorry, I forgot to attach files in hte last comment.
I used the view for testing only. Even with the mega tag not work too.


Reply to this email directly or view it on GitHub
https://github.com/Maatwebsite/Laravel-Excel/issues/188#issuecomment-51397361
.

You can find our extensive documentation at: http://www.maatwebsite.nl/laravel-excel/docs

@waister Are you sure the characters you get from the database (I guess they come from there) are UTF-8 encoded?

I tested it again with using , when I open the csv file in a text-editor the characters look fine.

@Maatwebsite Including worked for me. Thanks!

@MaatwebsiteSupport
Is there any way to export the csv file not in UTF-8. Such as Exporting file in SJIS for displaying the Japanese.

Also, you can try utf8_encode(string) before writing to a cell.
However I don{t know if this would work when writing array, model or view

Did anyone solve the issue because I'm having problem too..
when I'm trying to export the CSV, it's not what i actually should see, it's showing some kind of japanese while I tried to open with excel?
Is that the problem with excel or something else?

Please add the following code before download excel

ob_end_clean(); ob_start();

for who still get this problem, try edit config/excel.php : from 'use_bom' => false to 'use_bom' => true

@manhtqb Simple and clear, thanks!

if anyone see this,

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!

This issue still remains during import of CSV files. I did set use_bom to true, but formatting issues are still appearing.

i still have the same issue, i changed the value : 'use_bom' to true but when i open de csv file in excel, the econding problem persist.

i still have the same issue, i changed the value : 'use_bom' to true but when i open de csv file in excel, the econding problem persist.

You're replying to a very old ticket. Please open a new issue (and fill in the issue template details) if you're experiencing issues on Laravel Excel 3.1 version. Older versions of Laravel Excel are no longer supported. Thanks!

para quienes aún tienen este problema, intente editar config / excel.php: de 'use_bom' => falsea'use_bom' => true

Me salvaste el dia joven excelente!

Was this page helpful?
0 / 5 - 0 ratings