Laravel-excel: [QUESTION] Cell's value is returned as false

Created on 27 Sep 2017  Â·  3Comments  Â·  Source: Maatwebsite/Laravel-Excel

I'm using Laravel Excel 2.1. Laravel 5.4.3.

I'm trying to read a CSV file. The problem is, some cells are converted to false when they should be strings.

Here is an example of the first row of the file: 11/10/2016 11:35,91,241,Dundee Students Association,Liar Bar,dusa-2988,Payment,�1.80,�0.00,�1.80. � is actually \ufffd.

The problem only concerns the three last rows. When I read the file:

Excel::filter('chunk')->load($file_path)->chunk(250, function($sheets_collection)
{
    foreach ($sheets_collection as $current_sheet) {
        foreach ($current_sheet as $current_row) {
            // process $current_row
        }
    }
}, 'UTF-8');

$current_row contains the correct values for everything, except the three last cells which only contain false. Instead of getting false, I would like to get strings.

However, if I remove all the � only from the first row, it works fine not only for the first row but also for the rest!
The first row is read as the following array: ["11\/10\/2016 11:35",91,241,"Dundee Students Association","Liar Bar","dusa-2988","Payment",1.8,0,1.8].
The second row is read as the following array: ["11\/10\/2016 11:35",91,241,"Dundee Students Association","Liar Bar","dusa-3461","Payment","\ufffd1.10","\ufffd0.00","\ufffd1.10"]. All the subsequent rows are read in a similar fashion to the second row.
I cannot sanitise the first row for every file I plan to process, so is there a way to set Laravel-Excel to fetch the value from the cell correctly as a string?

Most helpful comment

@marijnz0r Thank you so much!
I used to have a problem like this with ° character.
To solve my problem I did that :
Config::set('excel.import.encoding.input', 'windows-1252'); Config::set('excel.import.encoding.output', 'windows-1252');

All 3 comments

The same problem arises for me when using characters like ’ and é. Have you found a solution yet?
Edit: changing the character encoding to windows-1252 worked for me.

@marijnz0r Thank you so much!
I used to have a problem like this with ° character.
To solve my problem I did that :
Config::set('excel.import.encoding.input', 'windows-1252'); Config::set('excel.import.encoding.output', 'windows-1252');

Tks a lot help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gamevnlc picture gamevnlc  Â·  3Comments

wwendorf picture wwendorf  Â·  3Comments

alejandri picture alejandri  Â·  3Comments

rossjcooper picture rossjcooper  Â·  3Comments

amine8ghandi8amine picture amine8ghandi8amine  Â·  3Comments