### Install Filament Excel with Composer Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This command installs the Filament Excel package and its dependency, Laravel Excel, using Composer. It ensures compatibility with specific PHP and Filament versions. ```bash composer require pxlrbt/filament-excel ``` -------------------------------- ### Create Custom Export Class Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This example shows how to extend the `ExcelExport` class to create a reusable custom export. The `setUp()` method allows for defining filename, columns, and other export configurations. ```php 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'), ]); } } ``` -------------------------------- ### Install Local Filament Excel Package via Composer Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This JSON snippet configures Composer to install the filament-excel package from a local path. It specifies a development version and adds a repository type to point to the local directory. This is useful for testing local changes before merging. ```json { "require": { "pxlrbt/filament-excel": "dev-fix/error-message as main-dev" }, "repositories": [ { "type": "path", "url": "filament-excel" } ] } ``` -------------------------------- ### Install Filament Excel with PSR Simple Cache for Laravel 9+ Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md For Laravel 9+ users experiencing issues with the simple-cache dependency, this command installs Filament Excel along with the specified version of 'psr/simple-cache' to resolve conflicts. ```bash composer require psr/simple-cache:^2.0 pxlrbt/filament-excel ``` -------------------------------- ### Enable Queued Exports Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This example enables background processing for large exports using the `queue()` method. This prevents long waits for users and provides notifications upon completion. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make()->queue() ]) ``` -------------------------------- ### Enable User Input for Filename and Writer Type Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This example demonstrates how to configure the ExportAction to allow users to specify the filename and the Excel writer type interactively. It utilizes the `askForFilename()` and `askForWriterType()` methods. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make() ->askForFilename() ->askForWriterType() ]) ``` -------------------------------- ### Set Export Filename with String or Closure Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This PHP example demonstrates setting the export filename using either a static string (e.g., 'YYYY-MM-DD - export') or a Closure that dynamically generates the filename, such as using the resource's label. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ // Pass a string ExcelExport::make()->withFilename(date('Y-m-d') . ' - export'), // Or pass a Closure ExcelExport::make()->withFilename(fn ($resource) => $resource::getLabel()) ]) ``` -------------------------------- ### Customize Signed Download URL for Exports Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This snippet shows how to customize the generation of signed URLs for accessing exported files. It allows for defining a custom route and adjusting the URL expiration time, potentially bypassing WAF restrictions. ```php // Somewhere in a ServiceProvider in the `boot()` method. use pxlrbt\FilamentExcel\FilamentExport; FilamentExport::createExportUrlUsing(function ($export) { $fileInfo = pathinfo($export['filename']); $filenameWithoutExtension = $fileInfo['filename']; $extension = $fileInfo['extension']; return URL::temporarySignedRoute( 'your-custom-route', now()->addHours(2), ['path' => $filenameWithoutExtension, 'extension' => $extension] ); }); ``` -------------------------------- ### Apply Number Formatting to Columns Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Shows how to apply specific number formatting to columns using PhpSpreadsheet's `NumberFormat` constants, such as currency formatting. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; use pxlrbt\FilamentExcel\Columns\Column; use PhpOffice\PhpSpreadsheet\Style\NumberFormat; ExportAction::make()->exports([ ExcelExport::make()->withColumns([ Column::make('currency')->format(NumberFormat::FORMAT_CURRENCY_EUR_INTEGER) ]), ]) ``` -------------------------------- ### Format Column States using Closures Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Explains how to format the state of individual columns within an Excel export using Closures. This allows for dynamic data transformation, accessing both the state and the record. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; use pxlrbt\FilamentExcel\Columns\Column; ExportAction::make()->exports([ ExcelExport::make()->withColumns([ Column::make('email') ->formatStateUsing(fn ($state) => str_replace('@', '[at]', $state)), Column::make('name') ->formatStateUsing(fn ($record) => $record->locations->pluck('name')->join(','), ]), ]) ``` -------------------------------- ### Add ExportBulkAction to Filament Resource (Admin Package) Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This PHP code demonstrates how to add the `ExportBulkAction` to the bulk actions of a Filament resource's table. It requires the `pxlrbt/FilamentExcel/Actions/Tables/ExportBulkAction` class. ```php columns([ // ]) ->bulkActions([ ExportBulkAction::make() ]); } } ``` -------------------------------- ### Manually Define Export Columns Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Allows manual definition of columns for Excel exports using `ExcelExport::make()->withColumns()`. Supports adding specific columns like 'name', 'created_at', and 'deleted_at'. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; use pxlrbt\FilamentExcel\Columns\Column; ExportAction::make()->exports([ ExcelExport::make()->withColumns([ Column::make('name'), Column::make('created_at'), Column::make('deleted_at'), ]), ]) ``` -------------------------------- ### Subset Export Columns with `only()` and `except()` Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Demonstrates how to selectively include or exclude columns from an Excel export using the `->only()` and `->except()` methods on `ExcelExport`. This is useful for exporting specific data subsets. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make()->fromTable()->except([ 'created_at', 'updated_at', 'deleted_at', ]), ExcelExport::make()->fromTable()->only([ 'id', 'name', 'title', ]), ]) ``` -------------------------------- ### Configure Multiple Export Types (Table and Form) Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This PHP snippet configures an `ExportAction` to offer multiple export types: 'table' and 'form'. It utilizes `ExcelExport::make()` and specifies the export source using `fromTable()` or `fromForm()`. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make('table')->fromTable(), ExcelExport::make('form')->fromForm(), ]) ``` -------------------------------- ### Configure Multiple Sheets for Export Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This code illustrates how to export data into multiple sheets within a single Excel file. It shows how to add custom sheets before, after, or as a replacement for the default data sheet. ```php ExportBulkAction::make()->exports([ ExcelExport::make('user_export')->fromTable() ->withSheets( sheets: [ new OverriddenDataSheet(), ], prepend: [ new CoverSheet(), ], append: [ new AppendixSheet(), ] ) ]) ``` -------------------------------- ### Set Custom Column Widths Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Demonstrates how to set a specific width for an Excel column using the `->width()` method. This overrides the default auto-scaling behavior. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; use pxlrbt\FilamentExcel\Columns\Column; ExportAction::make()->exports([ ExcelExport::make()->withColumns([ Column::make('email')->width(10) ]), ]) ``` -------------------------------- ### Customize Export Filename with Closure Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This PHP code customizes the export filename using a Closure passed to `withFilename()`. The Closure receives the `$resource` variable, allowing dynamic filename generation based on the resource label. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make('table')->withFilename(fn ($resource) => $resource::getLabel()), ]) ``` -------------------------------- ### Add ExportBulkAction to Separate Table Package Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This PHP code shows how to implement `ExportBulkAction` for a separate table package. It defines the `getTableBulkActions` method to return an array containing the `ExportBulkAction` instance. ```php exports([ ExcelExport::make() ->askForFilename() ->withFilename(fn ($filename) => 'prefix-' . $filename) ]) ``` -------------------------------- ### Adjust Queued Export Chunk Size Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This snippet demonstrates how to control the number of records processed per job in a queued export. Adjusting the chunk size with `withChunkSize()` can optimize performance for large datasets. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make()->queue()->withChunkSize(100) ]) ``` -------------------------------- ### Modify Export Query Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This code shows how to alter the database query used for exporting data. The `modifyQueryUsing()` method accepts a Closure that can add conditions, eager loads, or other query manipulations. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make() ->fromTable() ->modifyQueryUsing(fn ($query) => $query->where('exportable', true)) ]) ``` -------------------------------- ### Ignore Formatting in Exports Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Illustrates how to disable default formatting for all columns or specific columns using `->ignoreFormatting()`. This can be applied globally, to a list of columns, or conditionally via a Closure. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; use pxlrbt\FilamentExcel\Columns\Column; ExportAction::make()->exports([ // Ignore all formatting ExcelExport::make()->fromTable()->ignoreFormatting() // Ignore specific columns ExcelExport::make()->fromTable()->ignoreFormatting([ 'created_at', 'updated_at', ]), // Ignore columns based on Closure ExcelExport::make()->fromTable()->ignoreFormatting( fn (Column $column) => Str::startsWith($column->getName(), 'customer_') ), ]) ``` -------------------------------- ### Customize Column Headings Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md Shows how to override default column headings in Excel exports. You can set custom headings for specific columns using `Column::make()->heading()`. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; use pxlrbt\FilamentExcel\Columns\Column; ExportAction::make()->exports([ ExcelExport::make()->withColumns([ Column::make('name')->heading('User name'), Column::make('email')->heading('Email address'), Column::make('created_at')->heading('Creation date'), ]), ]) ``` -------------------------------- ### Set Export Writer Type (XLSX) Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This PHP snippet configures the export file type to XLSX using the `withWriterType()` method. It utilizes the `MaatwebsiteExcelExcel::XLSX` constant to specify the desired format. ```php use pxlrbt\FilamentExcel\Actions\Tables\ExportAction; use pxlrbt\FilamentExcel\Exports\ExcelExport; ExportAction::make()->exports([ ExcelExport::make()->withWriterType(\Maatwebsite\Excel\Excel::XLSX), ]) ``` -------------------------------- ### Customize ArrayFormatter Delimiter Source: https://github.com/pxlrbt/filament-excel/blob/main/readme.md This snippet shows how to customize the delimiter used by the ArrayFormatter in Laravel's service container. It allows users to specify a different separator for array values when exporting to Excel. ```php use pxlrbt\FilamentExcel\Exports\Formatters\ArrayFormatter; use Illuminate\Support\Facades\App; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function register() { App::bind(ArrayFormatter::class, function () { return new ArrayFormatter(';'); }); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.