Example #1
0
 public function replace(SheetInterface $sheet) : SpreadsheetInterface
 {
     if (!$this->has($sheet->name())) {
         throw new SheetNotFoundException();
     }
     $self = new self($this->name);
     $self->sheets = $this->sheets->put($sheet->name(), $sheet);
     return $self;
 }
Example #2
0
 private function buildFile(SheetInterface $sheet) : FileInterface
 {
     $csv = tmpfile();
     $columns = $sheet->columns()->keys()->sort(function ($a, $b) : bool {
         return $a > $b;
     })->toPrimitive();
     $default = array_fill_keys(array_values($columns), '');
     if ($this->withHeader) {
         fputcsv($csv, $columns, $this->delimiter);
     }
     $sheet->rows()->values()->sort(function (RowInterface $a, RowInterface $b) : bool {
         return $a->identifier() > $b->identifier();
     })->reduce($csv, function ($carry, RowInterface $row) use($default) {
         fputcsv($carry, $this->fill($default, $row->cells()), $this->delimiter);
         return $carry;
     });
     return new Csv($sheet->name(), new Stream($csv));
 }
 public function add(SheetInterface $sheet)
 {
     $this->_sheets[$sheet->getName()] = $sheet;
 }