Laravel-excel: Empty row repeated as array on import

Created on 3 Jun 2017  路  4Comments  路  Source: Maatwebsite/Laravel-Excel

i am using latest version of laravel-excel and in laravel 5.2.
when i import data from excel file i have only 2 records in excel file while i read through reader it gives me 398 elements of array which should be only 2.
in short laravel excel didn't ignore empty rows.
can any body help me on this?

   Config::set('excel.import.heading', 'original');
   \Excel::load($fileName, function ($reader) {
        $results = $reader->all()->toArray();
        $this->getImportData = $results;
    });

here result will be like this in this first 2 records i will get as it supposed to be and then remaining extra array is generated which should not be there. this problem occur only in excel not in csv

[3] => Array
    (
        [CustomerName] => 
        [email] => 
        [organization_phone] => 
        [organization_fax] => 
        [organization_size] => 
        [Website] => 
        [IndustryID] => 
        [debit_number] => 
        [billing_type] => 
        [address_type] => 
        [Building] => 
        [Street] => 
        [CountryName] => 
        [ZIP] => 
        [City] => 
        [RegionName] => 
        [Note] => 
        [bank_name] => 
        [iban_number] => 
    )

Most helpful comment

inspired from https://github.com/PHPOffice/PHPExcel/issues/561

used codes below

$sheets = Excel::load($file, function ($reader) {
    $reader->formatDates(false);
})->get();

foreach ($sheets as $sheet) {
    foreach ($sheet as $rowObj) {

        $is_row_empty = true;
        foreach ($rowObj as $cell) {
            if($cell !== '' &&  $cell !== NULL) {
                $is_row_empty = false; //detect not empty row
                break;
            }
        }

        if($is_row_empty ) continue; // skip empty row
        $row = $rowObj->toArray();
    }
}

All 4 comments

+1

@bindesh
In config excel you can set
'ignoreEmpty' => true,

inspired from https://github.com/PHPOffice/PHPExcel/issues/561

used codes below

$sheets = Excel::load($file, function ($reader) {
    $reader->formatDates(false);
})->get();

foreach ($sheets as $sheet) {
    foreach ($sheet as $rowObj) {

        $is_row_empty = true;
        foreach ($rowObj as $cell) {
            if($cell !== '' &&  $cell !== NULL) {
                $is_row_empty = false; //detect not empty row
                break;
            }
        }

        if($is_row_empty ) continue; // skip empty row
        $row = $rowObj->toArray();
    }
}

@mabuak 'ignoreEmpty' => true, is leave all empty rows and any empty columns if between two columns. My data is like http://prntscr.com/knoapy
If I'm using 'ignoreEmpty' => true,
Data for second row
array('Demand','Dry Bulk','Seaborne Trade','31-12-2000','777.665827','Russia','Ukraine')
But I want
array('Demand','Dry Bulk','Seaborne Trade','31-12-2000',,'777.665827','Russia','Ukraine')
and remove all empty rows.
@patrickbrouwers is it possible?

Was this page helpful?
0 / 5 - 0 ratings