Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mh71's avatar
Level 1

The Laravel Excel wrapper to PhpSpreadsheet

I have an Export class function, with several sample style treatments (bold, italic, size):

class TransactionsExport implements FromCollection, WithHeadings, WithMapping, WithStyles
{
    public function styles(Worksheet $sheet)
    {
        return [
        // Style the first row as bold text.
        1    => ['font' => ['bold' => true]],

        // Styling a specific cell by coordinate.
        'B2' => ['font' => ['italic' => true]],

        // Styling an entire column.
        'C'  => ['font' => ['size' => 16]],
    ];
}

It works. I see that output on a spreadsheet that is generated by Laravel Excel.

But the PhpSpreadsheet on which Laravel Excel appears to be wrapped also provides for an alignment treatment--but written in PHP, according to its documentation:

$spreadsheet->getActiveSheet()->getStyle('A1:D4')->getAlignment()->setWrapText(true);

I've tried a million ways to guess how Laravel Excel might implement that, if it even does. I've tried variations on

'A' => ['alignment' => ['wrap' => true]],

All to no avail.

If I know that PhpSpreadsheet does probably provide for a text wrap, then how can a statement that is constructed like

$spreadsheet->getActiveSheet()->getStyle('A1:D4')->getAlignment()->setWrapText(true);

be stitched into that function reproduced above?

0 likes
3 replies
mh71's avatar
Level 1

It works! Ha! Thank you!

So the character case has a bearing there. I had even tried both "wraptext" as well other argument configurations that incorporated upper and lower case but not that one.

The question is answered. I obviously can't set a best answer. I want the question to show answered. The answers are the same. The only fair thing I can think to do is set it to the first one on the clock, and only because I want to show the question as answered on the question list.

1 like

Please or to participate in this conversation.