Skip to content

Commit

Permalink
Allow modify width in columns excel (#9)
Browse files Browse the repository at this point in the history
[skip ci]

* Comment code for transform always data (#2)

* Update composer.json

* Update composer.json

* Update composer.json

* Update composer.json

* Update composer.json

* Update composer.json

* Update to PHP 8.*

* add width in excel[skip ci]

* Update src/Exportable.php

* fixed error functional test

---------

Co-authored-by: Eliurkis Diaz <[email protected]>
Co-authored-by: Dariel Ramos <[email protected]>
  • Loading branch information
3 people authored Jul 26, 2023
1 parent fd73d22 commit d7aa041
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Exportable.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ private function exportOrDownload($path, $function, callable $callback = null)
$writer->addNewSheetAndMakeItCurrent();
}
}
if ($has_sheets) {
$this->resizeColumnWidths($writer->getCurrentSheet());
}

$writer->close();
}

Expand Down Expand Up @@ -336,4 +340,19 @@ public function setColumnsWidth($widths)

return $this;
}

/**
* @param $sheet
* @return void
*/
private function resizeColumnWidths($sheet): void
{
if (empty($this->columns_width) || empty($sheet)) {
return;
}

foreach (array_values($this->columns_width) as $key => $value) {
$sheet->setColumnWidth($value, $key + 1); // Excel start from column 1
}
}
}

0 comments on commit d7aa041

Please sign in to comment.