This guide provides a comprehensive walkthrough for creating an Excel report with multiple sheets using the PHPExcel library in Laravel. Below is a summary and explanation of each part:
1. Setting Up Dependencies
First, you need to install the maatwebsite/excel package via Composer:
bash1composer require maatwebsite/excel
Then, add the service provider and alias to your config/app.php file.
2. Controller Method
In your controller (ReportController), create a method that handles the request for generating an Excel report:
php1use App\Excels\Exports\MyExport; 2 3public function generateReport() 4{ 5 // Fetch data from database or any source 6 $sheet1 = ...; 7 $sheet2 = ...; 8 9 return Excel::download(new MyExport($sheet1, $sheet2), 'report.xlsx'); 10}
3. Export Class
Create an export class that implements WithMultipleSheets:
php1namespace App\Excels\Exports; 2 3use Maatwebsite\Excel\Concerns\WithMultipleSheets; 4use App\Excels\Exports\Sheets\MySheet; 5 6class MyExport implements WithMultipleShe 7 8[Read the full article at DEV Community](https://dev.to/raflizocky_/multiple-sheets-excel-export-in-laravel-9od) 9 10--- 11 12**Want to create content about this topic?** [Use Nemati AI tools](https://nemati.ai) to generate articles, social posts, and more.





