Reputation: 328
Learning Laravel, I face now Excel export.
Searching in the Intenet Laravel Excel (docs.laravel-excel.com) seems to be the better choice, but I'm findind it very difficult to style the sheets (colors, fonts, sizes, etc.)
I'm using global event listeners in my AppServiceProvider:
Sheet::listen(AfterSheet::class, function () {
Sheet::macro('color_tab', function (Sheet $sheet, string $color) {
$sheet->getDelegate()->getTabColor()->setRGB($color);
});
});
And then I use it in my Export class:
...
public function __construct($color) {
$this->color = $color;
}
...
use RegistersEventListeners;
...
public static function afterSheet(AfterSheet $event) {
// this is an error because it's a static method!
$event->sheet->color_tab($this->color);
}
The problem is that I have to color the tab whit the color given in the constructor, but I can't because all these method for styling the Excel are static.
How can I do this?
Is there another good library to export Excel? With an easier way of do the styling.
Thanks!
Upvotes: 0
Views: 362
Reputation: 328
Finally I decided to use directly PhpSpreadSheet library whithout using wrapper Laravel Excel
Upvotes: 1