Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exporting using ajax doesn't download the file #17

Closed
karunkshrestha opened this issue Feb 4, 2014 · 2 comments
Closed

exporting using ajax doesn't download the file #17

karunkshrestha opened this issue Feb 4, 2014 · 2 comments

Comments

@karunkshrestha
Copy link

If I call this route using ajax, I don't get a prompt to download the file. I can see the content by using firebug.

Route::get('courses',function(){
    $result = Courses::all();
                Excel::create('TestCSVCase')
                    ->sheet('SheetName')
                    ->with($result->toArray())->export('csv');
});
@MaatwebsiteSupport
Copy link
Contributor

Hey

As far as I know, it's not possible to set the download headers when doing an ajax request.

@daraghoshea
Copy link

Hi, I am looking at using the jquery file download plugin (http://johnculviner.com/jquery-file-download-plugin-for-ajax-like-feature-rich-file-downloads/) to mimic the effect of ajax downloading.

The plugin's method is dependent upon a header being sent when the file is being downloaded, but the LaravelExcelWriter::_download() method does not allow for the headers to be altered.

Ideally, an event could be fired allowing for the headers to be adjusted prior to being sent to LaravelExcelWriter::_setHeaders()

Perhaps the following code change could be considered:

Current

$this->_setHeaders(array(
        'Content-Type'        => $this->contentType,
        'Content-Disposition' => 'attachment; filename="' . $this->filename . '.' . $this->ext . '"',
        'Expires'             => 'Mon, 26 Jul 1997 05:00:00 GMT', // Date in the past
        'Last-Modified'       => Carbon::now()->format('D, d M Y H:i:s'),
        'Cache-Control'       => 'cache, must-revalidate',
        'Pragma'              => 'public'
    ));

Suggested

$headers = new Illuminiate\Support\Collection(array(
        'Content-Type'        => $this->contentType,
        'Content-Disposition' => 'attachment; filename="' . $this->filename . '.' . $this->ext . '"',
        'Expires'             => 'Mon, 26 Jul 1997 05:00:00 GMT', // Date in the past
        'Last-Modified'       => Carbon::now()->format('D, d M Y H:i:s'),
        'Cache-Control'       => 'cache, must-revalidate',
        'Pragma'              => 'public'
    ));

Event::fire('maatwebsite.excel.headers', $headers);

$this->_setHeaders( $headers->toArray() );

It's a great package, but unfortunately I probably couldn't use it without this flexibility. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants