PHP code example of asignua / filament-xlsx-export
1. Go to this page and download the library: Download asignua/filament-xlsx-export library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asignua / filament-xlsx-export example snippets
use Asignua\FilamentXlsxExport\Actions\XlsxExportAction;
protected function getHeaderActions(): array
{
return [
XlsxExportAction::make(),
];
}
use Asignua\FilamentXlsxExport\Actions\XlsxExportBulkAction;
$table->toolbarActions([
BulkActionGroup::make([
XlsxExportBulkAction::make(),
]),
]);
XlsxExportAction::make()
->title('Orders') // bold first row, also the sheet name
->footer(fn () => 'Generated '.now()->format('Y-m-d H:i')) // under the data and totals
->caption(fn (array $data, int $rowCount) => "Open orders, {$rowCount} rows")
->fileName(fn () => 'orders-'.now()->format('Y-m-d'))
->rowLimit(10_000)
->columnFormats([...]);
use Asignua\FilamentXlsxExport\ColumnFormat;
XlsxExportAction::make()->columnFormats([
'total' => ColumnFormat::make()->money('€')->sum(), // "€" #,##0.00 and a bold total row
'price' => ColumnFormat::make()->divideBy(100)->decimal(2), // stored in cents
'ratio' => ColumnFormat::make()->percent(1),
'weight' => ColumnFormat::make()->number('0.000'),
'zip' => ColumnFormat::make()->text(), // keeps "00123"
'created_at' => ColumnFormat::make('Created')->date('dd.mm.yyyy')->width(14),
'paid' => ColumnFormat::make()->boolean(),
'internal' => ColumnFormat::make()->exclude(), // never offered
'notes' => ColumnFormat::make()->unselected(), // offered, not ticked
'vat' => ColumnFormat::make('VAT') // virtual column
->value(fn (Order $record, $state, array $data) => $record->total * 0.2)
->decimal(2),
]);