The question is as short as the title. I import a *.csv file and it seems LaravelExcel can't handle umlauts and returns null.
Is there a way to get this working?
Can you share your code and can you see in which encoding (e.g. utf-8) your file is saved?
$file = $request['file']; // file upload
if ($file -> getClientOriginalExtension() == 'csv')
{
$results = Excel::load($file) -> get();
foreach ($results as $row)
{
// some stuff here
// "$row -> costumer_name" will be null if the corresponding field
// in the *.csv file contains umlauts
}
}
My *.csv file is created with MS Excel. I'm not sure about the encoding but I think it must be "Windows-1252".
Edit: Sorry for the closing and reopening. I clicked the wrong button.
Try saving the file as UTF-8.
The problem is the file is not generated by me. So I somehow need to "change" the encoding after uploading but before importing the file.
Ah sorry I misunderstood. Is it possible for you to upload the file so I can test with it?
Yes, here is the file: http://www.share-online.biz/dl/L6BA49ONLCUW
I hope it's okay for you that I upload it there. This isn't the orignial, I removed the not relevant stuff. About the file: Cell 1 is the column header. "kundenname" is german and means costumer name. I removed the orignial names and added some random names ^^ However, the file is reproducing the error. Names containing "盲, 枚, 眉, etc." will be "null" in the result. This is some sample code:
$file = $request['file'];
$results = Excel::load($file) -> get();
dd($results);
The data in the file is seperated by ";" but I changed that in the config.
Yes, that should be fine. Will have a look at it soon.
Sorry it took so long, but I've found a fix:
In your config set the encoding to iso-8859-1
'import' => array(
'encoding' => array(
'input' => 'iso-8859-1',
'output' => 'iso-8859-1'
)
)
)
Tested with the file you provided, I was able to see the umlauts when dumping the results.
Yes! Thank you very much :) That works perfectly!
hi, i have the same problem but even after changing encoding in th config, i still get a null value.
I import a *.csv file and then add values to a MySQL database, tables id db are encoded utf8_unicode_ci
I tried the solution here and it worked ! :)
Maatwebsite/Laravel-Excel/pull/31
Sorry it took so long, but I've found a fix:
In your config set the encoding to
iso-8859-1'import' => array( 'encoding' => array( 'input' => 'iso-8859-1', 'output' => 'iso-8859-1' ) ) )Tested with the file you provided, I was able to see the umlauts when dumping the results.
Hello sir. Where can I find the config? is that from laravel config.php?
Most helpful comment
Sorry it took so long, but I've found a fix:
In your config set the encoding to
iso-8859-1Tested with the file you provided, I was able to see the umlauts when dumping the results.