Hi, if there somebody that use this package and using angularjs as frontend. Please help me to figure out on downloading the files. I already did something like this in the backend
public function bookReport(){
$data = array(
array('data1', 'data2'),
array('data3', 'data4')
);
return \Maatwebsite\Excel\Facades\Excel::create('Filename', function($excel) use($data) {
$excel->sheet('Sheetname', function($sheet) use($data) {
$sheet->fromArray($data);
});
})->download('xls');
}
but it returned a gibberish value and not directly downloading the file
Hello,
Please use the provided github issue template (https://github.com/Maatwebsite/Laravel-Excel/blob/2.1/.github/ISSUE_TEMPLATE.md) which was automatically inserted on issue create. Without the template, we are not able to efficiently look at your issue/question/proposal.
Hi, i only want to know how to use Content-Disposition. since I tried using Laravel only project, the download and export works smoothly well. @MaatwebsiteSupport @patrickbrouwers
That doesn't answer my question. Please use the provided github issue template.
I have the exact same question, however i dont think it belongs here as it's not directly related to this library
Hi @michaeltansy ,
Here is how i proceeded to render file available to download with angular js:
Api side:
public function exportCsv(Request $request)
{
$table = $request->route('table');
$model = $this->loadModel($table);
$society_id = $request->route('id_me');
$rows = $model
->where('society_id', $society_id)
->get();
$rows = $rows->toArray();
Excel::create($table, function($excel) use ($rows, $table)
{
$excel->setTitle("Exportation of " . $table);
$excel->sheet($table', function($sheet) use ($rows)
{
$sheet->fromArray($rows);
});
})->download('xls');
}
Front end:
view:
<a ng-href="{{ fileUrl }}" download="file.xls">download</a>
Controller:
serviceMain.testGET(function(res, status, headers, config) {
if (res.status > 400 && res.status < 600)
alertMsg.send(res.status, "danger");
else {
var test = res;
var blob = new Blob([test], {type: 'xls'});
url = $window.URL || $window.webkitURL;
$scope.fileUrl = url.createObjectURL(blob);
}
}, function(err, status, headers, config) {
if (err)
alertMsg.send(err.error.message, "danger");
});
Hi @MehdiTAIEB & @patrickbrouwers got same issue
and i used a button in frontend to download the excel file...
a sample plunk is here...
Did you solve the problem? I would like to know how I am in the same situation now