How to horizontally align text in all cells?

28 Views Asked by At

Using Laravel-Excel version 3.1.48

I am trying to center text in the spreadsheet using defaultStyles but it doesn't work:

    public function defaultStyles(Style $defaultStyle)
    {
        return [
            'alignment' => [
                'horizontal' => Alignment::HORIZONTAL_CENTER,
                'vertical' => Alignment::VERTICAL_CENTER,
                'wrapText' => true,
            ],
        ];
    }

I tested and defaultStyles does work for other styles like background color.

For example, the following works and sets all cells background color to red:

    public function defaultStyles(Style $defaultStyle)
    {
        return [
            'fill' => [
                'fillType'   => Fill::FILL_SOLID,
                'startColor' => ['argb' => Color::COLOR_RED],
            ],
        ];
    }

I then tried to horizontally center an individual cell using styles and it does work:

    public function styles(Worksheet $sheet)
    {
        return [
            'A1' => ['alignment' => ['horizontal' => Alignment::HORIZONTAL_CENTER]]
        ];
    }

Why is it not working for all the cells?

0

There are 0 best solutions below