SpartnerNL / Laravel-Excel

🚀 Supercharged Excel exports and imports in Laravel
https://laravel-excel.com
MIT License
12.28k stars 1.92k forks source link

allow alter http headers before they get sent prior to download #296

Closed daraghoshea closed 9 years ago

daraghoshea commented 9 years ago

In order to facilitate the use of a jquery plugin that implements an ajax like downloading experience: http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads

The implementation requires a particular header to be sent back as part of the server side response which currently cannot be done within the LaravelExcelWriter::_download() method.

Utilising an event prior to sending headers would allow the default headers to be flexibly adjusted as required.

MaatwebsiteSupport commented 9 years ago

1.3.0 will have the ability to pass an array of headers as the 2nd parameter of the export() method:

->export('xls', [
     'Set-Cookie'  => 'fileDownload=true; path=/'
]);
andreshg112 commented 5 years ago

How can I do this with version 3.1?

conradfuhrman commented 4 years ago

@andreshg112 you can add the use Exportable; Concern to the class e.g.

class MyExportClass implements FromView
{

  use Exportable;

}

Then in your controller you can add the header:

return (new MyExportClass())->download('myexportfile.xlsx', \Maatwebsite\Excel\Excel::XLSX, [
      'X-Vapor-Base64-Encode' => 'True'
    ]);

Documentation is here, took me a bit to figure out as well: https://docs.laravel-excel.com/3.1/exports/exportables.html

nsmet commented 11 months ago

@conradfuhrman That worked! You my friend saved my sanity today 🤘