lundi 6 avril 2020

Export excel using Maatwebsite 3.1 in laravel 5.8

Through ajax call need to export Maatwebsite\Excel and am using laravel 5.7 and maatwebsite 3.1. My code: In Script:

$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});

$.ajax({
    url: APP_URL + '/report/export-excel',
    method: "POST",
    //dataType: "json",
    data: {"data":data,"rtype":rtype},
    success: function(data) {
        console.log(data);
        location.href = APP_URL +data;
        console.log(data);

    },
});

In Controller:

Excel::store($draw,'filename.xls', function($excel) use($draw) {
$excel->sheet('Backup', function($sheet) use($draw) {
$datasheet = array();
$datasheet[0]  =   array('Partner Name','Quote Id','Sales Order','Customer Name','Amount','Created Date','Expired Date');
$i=1;
if(count($draw)>0){
foreach($draw as $key=>$datanew){
    $datasheet[$i] = array(
    $datanew['partner_name'],
    $datanew['quote_name'],
    $datanew['sales_order_no'],
    $datanew['customer_name'],
    $datanew['created_at'],
    $datanew['expiry_date']
    );
    $i++;
}
}
$sheet->fromArray($datasheet, null, 'A1', false, false);
$sheet->setHeight(1, 30);
$sheet->cell('A1:S1', function($cell) {
$cell->setAlignment('center');
$cell->setFont(array(
'size'       => '14',
'bold'       =>  true
));
});
});

})->store('csv', '/public/uploads/pdf/', true);

It seems version issue.Provide proper syntax for maatwebsite 3.1.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire