public function it_can_use_a_different_data_range(ContainerInterface $container, SpreadsheetInterface $spreadsheet) { $spreadsheet->getWorksheets()->willReturn(['tab1', 'tab2', 'tab3', 'included']); $this->beConstructedWith('path', array('label_row' => 2, 'data_row' => 4, 'include_worksheets' => array('/included/'))); $this->setContainer($container); $this->rewind(); $values = array(array('tab4_column1' => 'tab4_value1', 'tab4_column2' => 'tab4_value2'), array('tab4_column1' => 'tab4_value3', 'tab4_column2' => 'tab4_value4')); foreach ($values as $row) { $this->current()->shouldReturn($row); $this->next(); } $this->valid()->shouldReturn(false); }
/** * Parse the workbook. * * @param SpreadsheetInterface $workbook * * @return SheetCollection */ public function parse(SpreadsheetInterface $workbook) { // Init sheet collection $collection = new SheetCollection(); // Sheet parser $parser = new SheetParser($this->settings); // Loop through all worksheets foreach ($workbook->getWorksheets() as $worksheet) { $index = $workbook->getWorksheetIndex($worksheet); if ($this->isSelected($index)) { // Push the sheet onto the workbook $collection->push($parser->parse($workbook, $worksheet, $index)); } } return $collection; }
/** * Get the heading. * * @param SpreadsheetInterface $workbook * @param $sheetIndex * * @return array */ protected function getHeading(SpreadsheetInterface $workbook, $sheetIndex) { // Fetch the first row $row = $workbook->createRowIterator($sheetIndex, $this->settings->getRowIteratorSettings()); // Set empty labels array $heading = []; // Loop through the cells foreach ($row as $index => $values) { if ($index == $this->settings->getHeadingRow()) { foreach ($values as $cell) { $heading[] = $this->getIndex($cell); } return $heading; } } return $heading; }