Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize cells #191

Open
galegobr01 opened this issue Apr 11, 2024 · 4 comments
Open

Customize cells #191

galegobr01 opened this issue Apr 11, 2024 · 4 comments

Comments

@galegobr01
Copy link

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

@pxlrbt
Copy link
Owner

pxlrbt commented Apr 12, 2024

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

@yukebrillianth
Copy link

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?

@Priet
Copy link

Priet commented Oct 21, 2024

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!

@pxlrbt
Copy link
Owner

pxlrbt commented Oct 22, 2024

@Priet Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants