如何使用Laravel Excel重命名文件 - > download()

Ars*_*mov 5 php excel laravel

在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');
Run Code Online (Sandbox Code Playgroud)

当我在等待"test.xlsx"时,它给了我"bill.template.xlsx"

fid*_*per 8

我以前没有使用过这个库,但看看代码看起来你可以设置filename属性,然后在头文件中使用它来设置下载文件的名称.

可能是这样的:

Excel::load(public_path().'/bills/bill.template.xlsx', function($doc) 
{...})
    ->setFilename('whatever')
    ->download('xlsx');
Run Code Online (Sandbox Code Playgroud)