Beispiel #1
0
 /**
  * @param array $row
  *
  * @return CellCollection
  */
 public function parse(array $row = [])
 {
     $cells = [];
     foreach ($row as $index => $cell) {
         $index = $this->settings->getHasHeading() && isset($this->heading[$index]) ? $this->heading[$index] : $index;
         $cells[$index] = $cell;
     }
     return new CellCollection($cells);
 }
Beispiel #2
0
 public function test_parse_with_selected_sheets()
 {
     $settings = new ParserSettings();
     $settings->setSheetIndices([1]);
     $parser = new WorkbookParser($settings);
     $parsed = $parser->parse($this->mockWorkbook());
     $this->assertInstanceOf('Maatwebsite\\Clerk\\Excel\\Collections\\SheetCollection', $parsed);
     $this->assertEquals('mocked', $parsed->getTitle());
     $this->assertCount(1, $parsed);
 }
Beispiel #3
0
 /**
  * @param PHPExcel_Worksheet_Row $row
  *
  * @return CellCollection
  */
 public function parse(PHPExcel_Worksheet_Row $row)
 {
     $iterator = $row->getCellIterator();
     $iterator->setIterateOnlyExistingCells($this->settings->getIgnoreEmpty());
     $cells = [];
     foreach ($iterator as $index => $cell) {
         $index = $this->settings->getHasHeading() && isset($this->heading[$index]) ? $this->heading[$index] : $this->getIndexFromColumn($cell);
         $cells[$index] = new Cell($cell, $index, $this->settings);
     }
     return new CellCollection($cells);
 }
Beispiel #4
0
 public function test_parse_with_max_rows()
 {
     $settings = new ParserSettings();
     $settings->setHasHeading(false);
     $settings->setMaxRows(1);
     $parser = new SheetParser($settings);
     $parsed = $parser->parse($this->mockSheet());
     $this->assertInstanceOf('Maatwebsite\\Clerk\\Excel\\Collections\\RowCollection', $parsed);
     $this->assertEquals('mocked', $parsed->getTitle());
     $this->assertCount(1, $parsed);
 }
Beispiel #5
0
 public function test_parse_with_heading_with_original()
 {
     $settings = new ParserSettings();
     $settings->setHeadingType('original');
     $parser = new HeadingParser($settings);
     $parsed = $parser->parse($this->mockSheet());
     $this->assertTrue(is_array($parsed));
     $this->assertCount(2, $parsed);
     $this->assertContains('Name', $parsed);
     $this->assertContains('Date of Birth', $parsed);
 }
Beispiel #6
0
 public function test_getting_date_value()
 {
     $settings = new ParserSettings();
     $cell = $this->mockCell('39682');
     $this->assertInstanceOf('Carbon\\Carbon', $cell->getDateValue());
     $settings->setNeedsDateFormatting(false);
     $cell = $this->mockCell('39682', $settings);
     $this->assertEquals('39682', $cell->getDateValue());
     $settings->setNeedsDateFormatting(true);
     $settings->setDateFormat('d-m-Y');
     $cell = $this->mockCell('39682', $settings);
     $this->assertEquals('22-08-2008', $cell->getDateValue());
 }
Beispiel #7
0
 /**
  * Get slugged index.
  *
  * @param string $value
  * @param bool   $ascii
  *
  * @return string
  */
 protected function getSluggedIndex($value, $ascii = false)
 {
     // Get original
     $separator = $this->settings->getSeparator();
     // Convert to ascii when needed
     if ($ascii) {
         $value = $this->getAsciiIndex($value);
     }
     // Convert all dashes/underscores into separator
     $flip = $separator == '-' ? '_' : '-';
     $value = preg_replace('![' . preg_quote($flip) . ']+!u', $separator, $value);
     // Remove all characters that are not the separator, letters, numbers, or whitespace.
     $value = preg_replace('![^' . preg_quote($separator) . '\\pL\\pN\\s]+!u', '', mb_strtolower($value));
     // Replace all separator characters and whitespace by a single separator
     $value = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $value);
     return trim($value, $separator);
 }
Beispiel #8
0
 /**
  * Check if cell needs calculating.
  *
  * @return bool
  */
 protected function needsCalculatedValue()
 {
     return $this->settings->getCalculatedCellValues();
 }
Beispiel #9
0
 /**
  * Check if we didn't read the limit yet.
  *
  * @param $index
  *
  * @return bool
  */
 protected function hasReachedLimit($index)
 {
     return $this->settings->getMaxRows() && $index > $this->settings->getMaxRows() ? true : false;
 }
Beispiel #10
0
 /**
  * Check if sheet is selected.
  *
  * @param $index
  *
  * @return bool
  */
 protected function isSelected($index)
 {
     $sheets = $this->settings->getSheetIndices();
     return empty($sheets) || in_array($index, $sheets);
 }