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
How to: save csv/xls files using ajax only #848
Comments
Thank you very much it works good for CSV but not xls , |
I needed to return an xlsx from ajax, so I tweaked again a little and this is what I end up with: PHP
js
|
thanks!! |
i am getting "Class 'Excel' not found" Error .could u please help me? |
@randomhoodie any source how you came out with that solution? |
@eldyvoon like I said, "I tweaked" the original answer, take away what I didn't need, make it compact, and duckduckgo (search engine) for the mime type of ms office xlsx extension, I wasn't sure it was gonna work until I tried it, but I did tried it before posting, and since it worked I posted it, in case anyone would find it useful. |
I found that no javascript nor ajax is needed at all. I have a web page with links to download a bunch of different csv/xls/xlsx files and i don't want the page refreshing at all. All i did was hook a link up to an action which returned the following... public function getSpreadsheet() { |
Wonderfull!!!! |
Thanks @randomhoodie! For the 3.x package, I would update your PHP with something like this, per the upgrade guide: $myFile = Excel::raw(new YOUR_Export_Class, \Maatwebsite\Excel\Excel::XLSX);
$response = array(
'name' => "filename", //no extention needed
'file' => "data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".base64_encode($myFile) //mime type of used format
);
return response()->json($response); |
Thanks @kynetiv, I use version 3.x, but I needed to put extension like: filename.xlsx |
If you are still having this issue in 2020. Note that version 3.x of Laravel excel has changed so here is the solution
Example:
define your custom disk location in config filesystem like this
this will ensure the excel file is not saved in the storage/app back to your javascript, download the file like this
call the download function by passing the filename and path after the download remember to go back to the server and remove the one stored on the server like this I hope this helps anyone finding it hard to download laravel-excel through ajax or javascript. |
so good |
Hi guys,
I've seen that some of us are trying to serve file from ajax request. After some research, i didn't found any clear solution to do it. Tweaking some of them, i successfully exported csv and xls data from an Ajax request. The thing is, manipulation is different if the filetype is xls, because of the encoding, so theres a bit of tweaks.
Data is coming from a typical Eloquent query, converted to Array:
PHP
JS
ps: this is not an issue
The text was updated successfully, but these errors were encountered: