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
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
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