laravel maatwebsite-excel change sheet direction

Viewed 1665

how can I change sheet direction in laravel maatwebsite excel package? I want to change from left to right.

A B C D

to:

D C B A

this is my code :

   $row =  $this->userRepository->getById(1);

        $data = $row;
        Excel::create('test', function ($excel) use($data) {

            $excel->sheet('sheet', function ($sheet) use($data) {
                $sheet->fromArray($data, null, 'A1', false, false);
                $sheet->row(1, function($row) {
                });

            });
        })->store('xlsx', storage_path('excel/exports'))->download('xlsx');
3 Answers
class TractsExport implements FromCollection,WithEvents
{

    public function registerEvents(): array
    {
        return [

            BeforeSheet::class  =>function(BeforeSheet $event){
                $event->getDelegate()->setRightToLeft(true);
            }
        ];
    }
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        retutn Tract::all();
}

as laravel-Excel is made based on phpExcel then you can use native phpExcel method to the $excel object or the $sheet object

here is the code to change the sheet direction

 $excel->sheet('sheet', function ($sheet) use($data) {
                $sheet->->setRightToLeft(true);
                $sheet->fromArray($data, null, 'A1', false, false);
                $sheet->row(1, function($row) {
                });
Related