Author: Antoine Guigan (antoine@akeneo.com)
Ejemplo n.º 1
0
 /**
  * reads the given sheet
  * @param $file
  * @param $sheet
  * @param $offset
  */
 protected function readSheet($file, $sheet, $offset = 0)
 {
     $this->logInfo(sprintf('Try to read sheet "%s" from file "%s"', $sheet, $file));
     $workbook = SpreadsheetParser::open($file);
     $worksheets = $workbook->getWorksheets();
     if (!array_key_exists($sheet, $worksheets)) {
         $this->logWarning(sprintf('Tried to read non existing sheet with index "%s" from file "%s"', $sheet, $file));
         return;
     }
     $properties = [];
     $rowIterator = $workbook->createRowIterator($sheet);
     foreach ($rowIterator as $rowIndex => $values) {
         if ($this->headerDetector->isHeader($rowIndex, $values)) {
             $properties = $this->describeProperties($values);
             continue;
         }
         if ($rowIndex < $offset) {
             continue;
         }
         if (!count($properties)) {
             continue;
         }
         $this->processValues($properties, $values);
     }
     if (empty($properties)) {
         $this->logWarning('No properties found to process');
     }
 }
Ejemplo n.º 2
0
 public function testMacroMsOfficeFile()
 {
     $spreadsheet = SpreadsheetParser::open(__DIR__ . '/fixtures/msoffice.xlsm');
     $this->assertEquals(['Feuil1', 'Feuil2', 'Feuil3'], $spreadsheet->getWorksheets());
     $this->assertIteratesThrough([3 => ['value1', '', '2014-12-15 00:00', '2015-01-15 12:16'], 5 => ['', 'value5']], $spreadsheet->createRowIterator(0));
     $this->assertIteratesThrough([6 => ['', 'test1']], $spreadsheet->createRowIterator(1));
     $this->assertIteratesThrough([1 => ['', '', '', 'test4']], $spreadsheet->createRowIterator(2));
 }
Ejemplo n.º 3
0
 /**
  * Get all sheets/rows.
  *
  * @param array $columns
  *
  * @return \Illuminate\Support\Collection
  */
 public function get($columns = [])
 {
     // Load the file
     ini_set('auto_detect_line_endings', true);
     $this->driver = SpreadsheetParser::open($this->file);
     // Set selected columns
     $this->settings()->setColumns($columns);
     return (new WorkbookParser($this->settings()))->parse($this->getWorkbook());
 }
Ejemplo n.º 4
0
 public function testReadFileWithForcedFormat()
 {
     $spreadsheet = SpreadsheetParser::open(__DIR__ . '/fixtures/test.txt', CsvParser::FORMAT_NAME);
     $this->assertEquals(['default'], $spreadsheet->getWorksheets());
     $this->assertIteratesThrough([1 => ['value', 'enclosed value', '15'], 2 => ['', 'value2', '']], $spreadsheet->createRowIterator(0));
 }