Laravel-excel: Special Characters like 帽 will convert a word into number 0 on import

Created on 25 Nov 2020  路  4Comments  路  Source: Maatwebsite/Laravel-Excel

Prerequisites
[x ] Have read and understood: https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/.github/SUPPORT.md
[x ] Checked if your Laravel Excel version is still supported: https://docs.laravel-excel.com/3.1/getting-started/support.html#supported-versions
Checked that your question isn't already asked before.
Filled in the entire issue template
Versions
PHP version: 7.2
Laravel version: 5.8
Package version: ^3.1
Description
I have a CSV file with some rows that has text/words that contain a special character like 帽, what happened is that when I tried to import the file the words with characters above or alike will be converted to 0. Not sure if it is related to encoding, I found some solutions in the StackOverflow but none of them seem to work.

Additional Information
I am using the ToModel
use Maatwebsite\Excel\Concerns\ToModel;

To reproduce this, just try to put a special character in one of the cell of your CSV, then import it like:
Excel::import(new CsvImport, request()->file('file'));

The resulting inserted data that has a special character will be stored as 0

question

Most helpful comment

Solution :-

https://docs.laravel-excel.com/3.1/imports/custom-csv-settings.html#available-settings
1) In Header use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
2) adding the WithCustomCsvSettings interface
3) Add this function in your config/excel.php file
public function getCsvSettings(): array
{
return [
'input_encoding' => 'ISO-8859-1'
];
}

@patrickbrouwers , thank you for reply

All 4 comments

You need to set the correct input encoding in the config https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/config/excel.php#L128

@patrickbrouwers , Not working i already use this.

We just call PhpSpreadsheet code to parse the Csv, you'll have to ask there or on Stackoverflow then.

Solution :-

https://docs.laravel-excel.com/3.1/imports/custom-csv-settings.html#available-settings
1) In Header use Maatwebsite\Excel\Concerns\WithCustomCsvSettings;
2) adding the WithCustomCsvSettings interface
3) Add this function in your config/excel.php file
public function getCsvSettings(): array
{
return [
'input_encoding' => 'ISO-8859-1'
];
}

@patrickbrouwers , thank you for reply

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alejandri picture alejandri  路  3Comments

bahmanyaghoobi picture bahmanyaghoobi  路  3Comments

contifico picture contifico  路  3Comments

daraghoshea picture daraghoshea  路  3Comments

muhghazaliakbar picture muhghazaliakbar  路  3Comments