如何重命名之前的文件->;使用Laravel Excel下载()


How to rename file before ->download() with Laravel Excel

在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

我以前没有使用过这个库,但从代码来看,你可以设置filename属性,然后在标题中使用该属性来设置下载文件的名称。

可能类似于:

Excel::load(public_path().'/bills/bill.template.xlsx', function($doc) 
{...})
    ->setFilename('whatever')
    ->download('xlsx');
$data = Excel::download($query, 'TimeSheetExport.xlsx');
$data->setContentDisposition('attachment','TimeSheetExport')->getFile()->move(public_path('xlsx/'), $data->getFile().'xlsx');

$query是我们的收藏品。

"TimeSheetExport.xlsx"->不会是我们的文件名

move()中,您可以在第二个参数中提供文件名,第一个参数将是该文件的位置