How can I set text align right in the column on the laravel Excel maatwebsite?

♀尐吖头ヾ 提交于 2019-12-18 09:38:39

问题


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?

来源:https://stackoverflow.com/questions/51733202/how-can-i-set-text-align-right-in-the-column-on-the-laravel-excel-maatwebsite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!