Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

excel

laravel

Can't find in docs of Laravel Excel how to give a new name for loaded file before give it for download. I've tried ->setTitle but it doesn't work.

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

It gives me "bill.template.xlsx" when I'm waiting for "test.xlsx"

like image 985
Arsen Ibragimov Avatar asked Dec 09 '15 16:12

Arsen Ibragimov


People also ask

How do I change a filename in laravel?

You can rename your uploaded file as you want . you can use either move or storeAs method with appropiate param. Save this answer. Show activity on this post.

How do you skip blank rows in Maatwebsite Excel 3.1 for model way import on laravel?

You have to create a collection and use it with a filter rather than an array. First trim the value as a space is not empty. Then make it a collection after that filter the empty row.

How do I import a large Excel file into laravel?

When dealing with big files, it's better to import the data in big chunks. You can enable this with filter('chunk') ; To import it into chunks you can use chunk($size, $callback) instead of the normal get() . The first parameter is the size of the chunk. The second parameter is a closure which will return the results.


1 Answers

I haven't used this library before, but looking at the code it looks like you can set the filename attribute which will then get used in the headers to set the name of the file downloaded.

Probably something like:

Excel::load(public_path().'/bills/bill.template.xlsx', function($doc) 
{...})
    ->setFilename('whatever')
    ->download('xlsx');
like image 116
fideloper Avatar answered Sep 30 '22 05:09

fideloper