filament-excel icon indicating copy to clipboard operation
filament-excel copied to clipboard

Customize cells

Open galegobr01 opened this issue 10 months ago • 4 comments

Is there any way to customize, for example: Alignment, type of data entered (text, number, general), cell coloring, etc.?

galegobr01 avatar Apr 11 '24 22:04 galegobr01

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

pxlrbt avatar Apr 12 '24 16:04 pxlrbt

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?

yukebrillianth avatar May 10 '24 11:05 yukebrillianth

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 avatar Oct 21 '24 09:10 Priet

@Priet Thanks for sharing.

pxlrbt avatar Oct 22 '24 10:10 pxlrbt