Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

laravel maatwebsite-excel change sheet direction

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');
like image 815
Hamid Naghipour Avatar asked Mar 08 '23 22:03

Hamid Naghipour


1 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();
}
like image 93
Hossein Esteki Avatar answered Mar 17 '23 06:03

Hossein Esteki