DEV Community

Cover image for How to Export Data To Excel file in Laravel 8
shani singh
shani singh

Posted on

How to Export Data To Excel file in Laravel 8

Export Laravel Excel

Export Data to Excel Files in Laravel 8

Today I am Going To Explain you about how you can Export Excel Files in Laravel 8.

I am going to use Tech-Admin Panel for this.

For Exporting excel file i am using Laravel Excel.

You can read about Laravel Import From CSV/ Excel Files Here!

Step 1 - Installation

To Install the Laravel Excel Package via composer run command below.

composer require maatwebsite/excel
Enter fullscreen mode Exit fullscreen mode

Next to export config file you need run command below.

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider" --tag=config
Enter fullscreen mode Exit fullscreen mode

Step 2 - Create an Exports Class inside app/Exports

Create Exports Class by using artisan command

php artisan make:export UsersExport --model=User
Enter fullscreen mode Exit fullscreen mode

Step 3 - Handle Export To Excel Function

public function export() 
{
   return Excel::download(new UsersExport, 'users.xlsx');
}
Enter fullscreen mode Exit fullscreen mode

You can watch the explanation video for more clarity.

Thank You for Reading

In case of any query related to LARAVEL.
Reach Out To me.
Twitter
Instagram

Top comments (1)

Collapse
 
msnmongare profile image
Sospeter Mongare

Thank you for sharing, however the excel extracted does not have headers