maatwebsite 中的换行文字不适用于 laravel

wrap text in maatwebsite is not working with laravel

我正在尝试从 A1 开始换行,但它不起作用并抛出错误 setStyle method is not found

Excel::create('complaint_report', function ($excel) use ($compsArray) {
    // Set the spreadsheet title, creator, and description
    $excel->setTitle('complaints report');
    $excel->setCreator('Laravel')->setCompany('Beegains, LLC');
    $excel->setDescription('complaints file');

    // Build the spreadsheet, passing in the comps array
    $excel->sheet('sheet1', function ($sheet) use ($compsArray) {
        $sheet->fromArray($compsArray, null,getStyle('A1')->getAlignment()->setWrapText(true), false, false);
    });
})->download('xlsx');

您不能在 sheet 上调用 getStyle 函数。只需更新为:

$sheet->fromArray($compsArray, null, 'A1', false, false)
    ->getStyle('A1')
    ->getAlignment()
    ->setWrapText(true);

你也可以用我的方法:

$sheet->fromArray([], null, 'A1', false, false)
->getStyle('A1')
->getAlignment()
->setWrapText(true);

A1 = 您的手机

这是结果: