Skip to content

Commit

Permalink
Update to reflect openspout changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jschram committed May 10, 2024
1 parent 1388b30 commit 37516bb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 1 addition & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,10 @@
"xlsx"
],
"description": "Fast Excel import/export for Laravel",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/jschram/openspout.git"
}
],
"require": {
"php": "^8.0",
"illuminate/support": "^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.0 || ^11.0",
"openspout/openspout": "4.x-dev"
"openspout/openspout": "^4.24"
},
"require-dev": {
"illuminate/database": "^6.20.12 || ^7.30.4 || ^8.24.0 || ^9.0 || ^10.0 || ^11.0",
Expand Down
16 changes: 13 additions & 3 deletions src/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private function addRowsWithStyle($writer, $all_rows, $rows_style, $column_style
$styled_rows = [];
// Style rows one by one
foreach ($all_rows as $row) {
$styled_rows[] = Row::fromValues($row->toArray(), $rows_style, $column_styles);
$styled_rows[] = $this->createRow($row->toArray(), $rows_style, $column_styles);
}
$writer->addRows($styled_rows);
}
Expand All @@ -227,7 +227,7 @@ private function writeRowsFromGenerator($writer, Generator $generator, ?callable
$this->writeHeader($writer, $item);
}
// Write rows (one by one).
$writer->addRow(Row::fromValues($item->toArray(), $this->rows_style, $this->column_styles));
$writer->addRow($this->createRow($item->toArray(), $this->rows_style, $this->column_styles));
}
}

Expand All @@ -248,7 +248,7 @@ private function writeHeader($writer, $first_row)
}

$keys = array_keys(is_array($first_row) ? $first_row : $first_row->toArray());
$writer->addRow(Row::fromValues($keys, $this->header_style));
$writer->addRow($this->createRow($keys, $this->header_style));
// $writer->addRow(WriterEntityFactory::createRowFromArray($keys, $this->header_style));
}

Expand Down Expand Up @@ -319,4 +319,14 @@ public function rowsStyle(Style $style)

return $this;
}

/**
* Create openspout row from values with optional row and cell styling
*
* @SuppressWarnings(PHPMD.StaticAccess)
*/
private function createRow(array $values = [], ?Style $rows_style = null, array $column_styles = []): Row
{
return Row::fromValuesWithStyles($values, $rows_style, $column_styles);
}
}

0 comments on commit 37516bb

Please sign in to comment.