Advertisement
aivavic

Untitled

Feb 26th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.74 KB | None | 0 0
  1. public function importExcel($function = null)
  2.     {
  3.         if ($this->upload_file()) {
  4.             Price::deleteAll();
  5.             if ($function) {
  6.                 $this->onImportRow = $function;
  7.             }
  8.             //$reader = \PHPExcel_IOFactory::createReader( /*$this->defaultFormat*/ );
  9.             $objPHPExcel = \PHPExcel_IOFactory::load($this->_uploaded_file->tempName);
  10.             $objWorksheet = $objPHPExcel->getActiveSheet();
  11.             $highestRow = $objWorksheet->getHighestRow();
  12.             $result = [];
  13.             $foo = [];
  14.             foreach ($objWorksheet->getRowIterator() as $i => $row) {
  15.                 $cellIterator = $row->getCellIterator();
  16.                 $cellIterator->setIterateOnlyExistingCells(false);
  17.                 $row = [];
  18.                 foreach ($cellIterator as $cell) $row[] = $cell->getValue();
  19.                 $foo = [$row[0] => $row[4]];
  20.                 if (!array_key_exists($row[0], $result)) {
  21.                     $result = array_merge($result, $foo);
  22.                 }
  23.             }
  24.             foreach ($objWorksheet->getRowIterator() as $i => $row) {
  25.                 $cellIterator = $row->getCellIterator();
  26.                 $cellIterator->setIterateOnlyExistingCells(false);
  27.                 $row = [];
  28.                 foreach ($cellIterator as $cell) $row[] = $cell->getValue();
  29.                 \yii\helpers\VarDumper::dump($row, 9, 9);
  30.                 $this->_current_row = $i;
  31.                 if ($this->import_row([
  32.                     'row' => $row,
  33.  
  34.                     'index' => $i,
  35.                     'max_row' => $highestRow
  36.                 ])
  37.                 ) {
  38.                 } else {
  39.                     break;
  40.                 }
  41.             }
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement