/** * Start the import * @param bool|callable $callback $callback * @throws \PHPExcel_Exception * @return void */ public function start($callback = false) { // Init a new sheet collection $this->sheetCollection = new SheetCollection(); // Get the sheet names if ($sheets = $this->excel->getSheetNames()) { // Loop through the sheets foreach ($sheets as $index => $name) { // Set sheet name $this->sheetName = $name; // Set sheet $this->sheet = $this->excel->setActiveSheetIndex($index); // Do the callback if ($callback instanceof Closure) { call_user_func($callback, $this); } else { $this->sheetCollection->push(clone $this); } } } }
/** * Parse the file * @param array $columns * @return SheetCollection */ public function parseFile($columns = array()) { // Init new sheet collection $workbook = new SheetCollection(); // Set the selected columns $this->setSelectedColumns($columns); // If not parsed yet if (!$this->isParsed) { // Set worksheet count $this->w = 0; // Get selected sheets $iterator = $this->excel->getWorksheetIterator(); // Loop through the worksheets foreach ($iterator as $this->worksheet) { // Check if the sheet might have been selected by it's index if ($this->reader->isSelectedByIndex($iterator->key())) { // Parse the worksheet $worksheet = $this->parseWorksheet(); // If multiple sheets if ($this->parseAsMultiple()) { // Push every sheet $workbook->push($worksheet); $workbook->setTitle($this->excel->getProperties()->getTitle()); } else { // Ignore the sheet collection $workbook = $worksheet; break; } } $this->w++; } } $this->isParsed = true; // Return itself return $workbook; }