Search code examples
laravel-5.8maatwebsite-excellaravel-excel

WithChunkReading reads rows beyond the maximum rows filled


I am trying to import excel file over 6610 records, with Maatwebsite-excel v3.1. I have implemented the import class that implements ChunkReading too. After inserting the last record in database,the excel-import implementation even considers 6611th record (6612th row) that is sending empty placeholders for data insertion in database.

Here is some code,

class UsersImport implements ToCollection, WithHeadingRow, WithChunkReading
{
    public $count = 0;

    public function collection(Collection $rows)
    {
        //insertion of $rows data in database
    }

    public function chunkSize() : int {
        return 300;
    }

}

I have been scratching my head since many hours. But I am unable to understand what is exactly happening.

I am using Ubuntu. And file format is .xlsx.

Kindly help me with the stuff. Thanks in advance.


Solution

  • It was simply a mistake of some white space left in the row beyond the filled rows. I purposefully deleted all the empty rows from 6612th row to max rows in that sheet, and my problem was solved.