在maatwebsite中包装文字无法与laravel一起使用

时间:2018-06-22 09:45:51

标签: php laravel laravel-5.5 laravel-5.6

我正在尝试从A1开始换行,但是它无法正常工作,并引发错误,找不到getStyle方法

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');

1 个答案:

答案 0 :(得分:1)

您不能在工作表上调用getStyle函数。只需更新至:

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