Exemplo n.º 1
0
 /**
  * Get all sheets/rows.
  *
  * @param array $columns
  *
  * @return \Illuminate\Support\Collection
  */
 public function get($columns = [])
 {
     // Load the file
     $this->driver = $this->reader->load($this->file);
     // Set selected columns
     $this->settings()->setColumns($columns);
     return (new WorkbookParser($this->settings()))->parse($this->getWorkbook());
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 /**
  * Compte le nombre de colonnes contenues dans le fichier.
  */
 protected function countColumns()
 {
     $excelReader = $this->reader->load($this->filename);
     $this->numberOfCols = $excelReader->getActiveSheet()->getHighestColumn();
     $excelReader->disconnectWorksheets();
     unset($excelReader);
 }
Exemplo n.º 4
0
 /**
  * @inheritDoc
  */
 public function init()
 {
     parent::init();
     foreach ($this->columns as $key => $column) {
         if (is_array($column)) {
             $this->columns[$key] = \Yii::createObject(ArrayHelper::merge(['activeDataProvider' => $this->activeDataProvider], $column));
         }
     }
     $this->activeDataProvider->pagination = ['defaultPageSize' => false, 'pageSizeLimit' => false];
     $this->reader = \PHPExcel_IOFactory::createReader(\PHPExcel_IOFactory::identify($this->filename));
     $this->reader->setReadDataOnly(true);
     $this->phpExcel = $this->reader->load($this->filename);
     $this->models = ArrayHelper::map($this->activeDataProvider->getModels(), 'primaryKey', function ($item) {
         return $item;
     });
 }
Exemplo n.º 5
0
 /**
  * Load file
  * @param string $file
  * @param bool $hasHeader
  * @return $this
  */
 public function load($file, $hasHeader)
 {
     //initialize
     $this->_init($file);
     $this->hasHeader = $hasHeader;
     if ($this->sheetSelected()) {
         $this->reader->setLoadSheetsOnly($this->selectedSheets);
     }
     $this->excel = $this->reader->load($this->file);
     return $this;
 }
 /**
  * @param $startRowIndex
  * @return \PHPExcel_Worksheet
  */
 private function reloadIterator($startRowIndex)
 {
     $this->filter->setRows($startRowIndex);
     $phpExcel = $this->reader->load($this->filename);
     $worksheet = $phpExcel->getSheet($this->sheetNumber - 1);
     $this->rowIterator = $worksheet->getRowIterator();
     $this->rowIterator->rewind();
     try {
         $this->rowIterator->seek($startRowIndex);
     } catch (\PHPExcel_Exception $ex) {
         //Edge case: the data source ends right at the end of this chunk, so the new chunk is empty and the seek
         //operation fails. Set the end to -1 to make the iterator invalid from now on
         $this->rowIterator->resetEnd(-1);
     }
     return $worksheet;
 }