dimanche 29 avril 2018

PhpSpreadsheet chunk filter read returning empty rows

I'm trying to read an XLSX file by chunks. But some of the chunks are empty on the var_dump out put. I'm using PHP7.2 and Laravel 5.5 framework.

That is what I've tried so far:

Filter

class ChunkReadFilter implements IReadFilter
{
private $startRow = 0;
private $endRow   = 0;

// Set the list of rows that we want to read  
public function setRows($startRow, $chunkSize) {
    $this->startRow = $startRow;
    $this->endRow   = $startRow + $chunkSize;
}

public function readCell($column, $row, $worksheetName = '') {
    //  Only read the heading row, and the configured rows
  // if (($row == 1) || ($row >= $this->startRow && $row < $this->endRow)) {
 if (($row >= $this->startRow && $row < $this->endRow)) {
        if (in_array($column, range('A', 'L'))) {
            return true;
        }

    }
    return false;
}
}

Code

$inputFileType = 'Xlsx';
$inputFileName = $path;

$reader = IOFactory::createReader($inputFileType);
$chunkSize = 100;
$chunkFilter = new ChunkReadFilter();
for ($startRow = 1; $startRow <= 800; $startRow += $chunkSize) {

     //Tell the Read Filter which rows we want this iteration  
    $chunkFilter->setRows($startRow,$chunkSize);
    //Tell the Reader that we want to use the Read Filter 
    $reader->setReadFilter($chunkFilter);
    //Load only the rows that match our filter  
    $spreadsheet = $reader->load($inputFileName);
    //Do some processing here
    $sheetData = $spreadsheet->getActiveSheet()
   ->toArray(null, true, true, true);

      var_dump($sheetData);
   }



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Kp4PQ3
via IFTTT

Aucun commentaire:

Enregistrer un commentaire