Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maatwebsite/Laravel-Excel Import converts special Characters into number 0

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 CSV file, the words with characters above or alike will be converted to 0.

I am using the ToModel

use Maatwebsite\Excel\Concerns\ToModel;

To reproduce this, just try to put a special character in one of the cells of your CSV file, then import it like:

Excel::import(new CsvImport, request()->file('file'));

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

Note: Adding data directly from the Form does not convert the special characters to 0, only when uploading CSV through import

like image 334
fmsthird Avatar asked Oct 17 '25 14:10

fmsthird


2 Answers

On your config set the 'use_bom' to 'true'

    'csv'                    => [
        'delimiter'              => ',',
        'enclosure'              => '"',
        'line_ending'            => PHP_EOL,
        'use_bom'                => true,
        'include_separator_line' => false,
        'excel_compatibility'    => false,
    ],
like image 185
mpalencia Avatar answered Oct 20 '25 17:10

mpalencia


This work for me:

$data = Excel::load('file.csv', false, 'ISO-8859-1');

Or in the file configuration of excel config/excel.php

      'csv'                    => [
        'delimiter'              => ';',
        'input_encoding'         => 'ISO-8859-1',
        'enclosure'              => '"',
        'line_ending'            => PHP_EOL,
        'use_bom'                => false,
        'include_separator_line' => false,
        'excel_compatibility'    => true,
    ],
like image 30
Gustavo Marquez Avatar answered Oct 20 '25 15:10

Gustavo Marquez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!