filament-excel
filament-excel copied to clipboard
Customize cells
Is there any way to customize, for example: Alignment, type of data entered (text, number, general), cell coloring, etc.?
You probably need to extend the Exportable and add the methods from laravel/excel
https://docs.laravel-excel.com/3.1/exports/column-formatting.html#styling
You probably need to extend the Exportable and add the methods from
laravel/excel
https://docs.laravel-excel.com/3.1/exports/column-formatting.html#styling
how to do it?
Maybe you figured it out already but I was looking for the same thing. For future reference, here is how I solved it.
First, create a custom export as explained here: https://github.com/pxlrbt/filament-excel?tab=readme-ov-file#custom-exports
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
use pxlrbt\FilamentExcel\Columns\Column;
class CustomExport extends ExcelExport
{
public function setUp()
{
$this->withFilename('custom_export');
$this->withColumns([
Column::make('name'),
Column::make('email'),
]);
}
}
Then make sure the class implements the WithStyles interface:
use Maatwebsite\Excel\Concerns\WithStyles;
class CustomExport extends ExcelExport implements WithStyles
{
....
At last, implement the public function styles:
class CustomExport extends ExcelExport implements WithStyles
{
...
public function styles(Worksheet $sheet)
{
return [
1 => ['font' => ['bold' => true]],
'D' => ['alignment' => ['horizontal' => 'right']],
];
}
In this example, the header row will be bold and the 4th column will be right aligned.
Hope this helps!
@Priet Thanks for sharing.