public function __construct($fileName, $csvDelimiter = null, $csvEnclosure = null, $sheetNumber = 1, $chunkSize = null, $fillMissingColumns = true, $removeCellsNotMatchingHeaderColumns = true) { $this->filename = $fileName; $this->sheetNumber = $sheetNumber; $this->fillMissingColumns = $fillMissingColumns; $this->removeCellsNotMatchingHeaderColumns = $removeCellsNotMatchingHeaderColumns; //@todo: Allow disabling chunked read $this->filter = new ChunkReadFilter(0, $chunkSize); $this->reader = \PHPExcel_IOFactory::createReaderForFile($this->filename); if ($this->reader instanceof \PHPExcel_Reader_CSV) { if ($csvDelimiter) { $this->reader->setDelimiter($csvDelimiter); } if ($csvEnclosure) { $this->reader->setEnclosure($csvEnclosure); } } $this->reader->setReadFilter($this->filter); $worksheet = $this->reloadIterator(1); $this->highestDataColumnName = $worksheet->getHighestDataColumn(); $this->highestRow = $worksheet->getHighestRow(); $this->rowIterator->rewind(); $this->header = $this->getFilteredArrayForCurrentRow(); foreach ($this->header as $headerIndex => &$columnHeader) { if (is_null($columnHeader) || $columnHeader === '') { $columnHeader = $headerIndex; } else { $columnHeader = trim($columnHeader); } } $this->rowIterator->next(); }
public function rewind() { if (is_null($this->worksheet)) { $this->reader->setReadFilter(new ReadFilter($this->maxRows, $this->maxCol)); /** @var \PHPExcel $excel */ $excel = $this->reader->load($this->file->getPathname()); if (null !== $this->activeSheet) { $excel->setActiveSheetIndex($this->activeSheet); } $this->worksheet = $excel->getActiveSheet()->toArray(); } parent::rewind(); }