I'm using Laravel 5.6 version and laravel-excel.maatwebsite version 3.1. I want to convert html to excel file.
In official documentation they have not given enough information to convert html views to excel. I'm having hard time.
Below is the Code for App\Exports\AttendanceExport
<?php
namespace App\Exports;
use App\Models\Student\StudentAttendenceModel;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use Maatwebsite\Excel\Concerns\FromCollection;
class AttendanceExport implements FromView {
protected $data = [];
public function __construct($data) {
$this->data = $data;
}
public function view(): View {
return view($this->data['file_path'], [
'data' => $this->data
]);
}
}
MY CONTROLLER CODE : Reports\ReportsFormProcessController
<?php
namespace App\Http\Controllers\Reports;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Redirect;
use App\Models\Student\StudentAttendenceModel;
//EXCEL
use App\Exports\AttendanceExport;
use Maatwebsite\Excel\Facades\Excel;
class ReportsFormProcessController extends Controller {
public function __construct() {
parent::__construct();
}
protected function processStdAttendance($data) {
$excel_query = [
'file_name' => 'test.xlsx',
'sheet_name' => 'sheet 11',
'file_path' => 'reports.excel_templates.test',
'query_results' => $info_array['query_results'], //THIS AS A RESULT FROM DB
];
$attendanceExport = new AttendanceExport($excel_query);
return $attendanceExport->view();
}
}
MY HTML TEMPLATE CONTAINS A TABLE BELOW
<!DOCTYPE html>
<html>
<title>HTML Tutorial</title>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
</body>
</html>
I'M NOT GETTING ANY ERRORS BY ALSO I'M NOT GETTING EXCEL FILE DOWNLOAD
THANKS IN ADVANCE
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire