I get reference from here : https://laravel-excel.maatwebsite.nl/3.0/getting-started/
I have been looking for how to set the text align right, but I did not find it in the documentation
My script export like this :
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\Exportable;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
class InvoiceExport implements FromView
{
use Exportable;
public function view(): View
{
$data = Invoice::get();
return view('exports.item', [
'data' => $data
]);
}
}
How can I solve this problem?
Update
I find a solution, but it's not perfect
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->styleCells(
'C2:C1000',
[
'alignment' => [
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_RIGHT,
],
]
);
},
];
}
It works. But my record is dynamic. It can be 1000 records. it can be 10000 records
In my script above, it just block from C2 to C1000. I want to set all records in column C
How can I do it?
exports.item
blade file, just use<td style="text-align: right;">...</td>
(or<td align="right"...
) where you want right-aligned Excel cells. This is for version 2.1, but I'm sure the logic still applies: laravel-excel.maatwebsite.nl/2.1/blade/… – Arch'C:C'
. – Jacalynjacamar$event->sheet->styleCells()
method isn't available... – Narva