如何使用Laravel Excel在 – > download()之前重命名文件
在Laravel Excel的文档中找不到在下载之前如何为加载的文件提供一个新名称。 我试过 – > setTitle,但它不起作用。
Excel::load(public_path().'/bills/bill.template.xlsx', function($doc) { $doc->setTitle = 'test'; $sheet = $doc->setActiveSheetIndex(0); $sheet->setCellValue('G21', '{buyer}'); $sheet->setCellValue('AB24', '{sum}'); $sheet->setCellValue('B30', '{sum_propis}'); })->download('xlsx');
当我等待“test.xlsx”时,它给了我“bill.template.xlsx”
我以前没有用过这个库,但是看看代码,你可以设置文件名属性 , 然后在头文件中使用它来设置下载文件的名称 。
可能是这样的:
Excel::load(public_path().'/bills/bill.template.xlsx', function($doc) {...}) ->setFilename('whatever') ->download('xlsx');