Avoiding empty columns and cells

Viewed 97

Im using laravel-excel to import a large volume of data that is in spreadsheets. These spreadsheets have the first column and the first 3 rows empty (as in the image below) and this is causing an unexpected return when the result is printed on screen:

Array ( [] => )
Array ( [] => )
Array ( [] => Email )
Array ( [] => jsimpson@email.com )
Array ( [] => spider@man.com )
Array ( [] => im@legend.com ) 

if I manually move the table's contents to the left and up, everything happens as it should be:

Array ( [firstname] => John [lastname] => Simpson [age] => 36 [email] => jsimpson@email.com )
...

How to avoid these empty columns and cells or move them?

spreadsheet exemple: enter image description here My code:

<?php
namespace App\Imports;

use App\Models\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class UserImport implements ToModel, WithHeadingRow 
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        return new User([
            'first_name' => $row['firstname'],
            'last_name' => $row['lastname'],
            'age' => $row['age'],
            'email' => $row['email'],
        ]);
    }
}
0 Answers
Related