当前位置:网站首页>Laravel8 export excel file
Laravel8 export excel file
2022-07-05 03:58:00 【s_ Canned ice cubes】
1. Reference resources Excle Official website .
2. Use composer Command to deploy Excle.
composer require maatwebsite/excel3. Use composer Command to create Excle The export model .
php artisan make:export UsersExport --model=User4. Click to enter the newly created Excle controller .

5. The contents of the document are modified

notes : If we export excle Header words , We need to inherit our header file .


Just write our exported method in our control :

Finally, call our method through the route :

Attach complete code :
Excle Content of model file :
<?php
namespace App\Exports;
use App\Models\AddlistModel;
use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;// export excle Header
class UsersExport implements FromCollection, WithHeadings
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
// Here we call the model we need to export data
return AddlistModel::all();
}
// Add the specified header
public function headings(): array
{
return [
'ID',
' title ',
' Text ',
' Creation time ',
' Modification time '
];
}
}
Controller code content :
// Export us Excl file
public function export()
{
return Excel::download(new UsersExport, 'excle.xlsx');
}边栏推荐
猜你喜欢

Clickhouse materialized view

C语言课设:影院售票管理系统
![[wp]bmzclub几道题的writeup](/img/15/2838b93a605b09d3e2996f6067775c.png)
[wp]bmzclub几道题的writeup

【软件逆向-基础知识】分析方法、汇编指令体系结构

Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation

Timing manager based on C #

v-if VS v-show 2.0

Subversive cognition: what does SRE do?

Pyqt pyside custom telescopic menu bar sharing (including tutorial)

How to use jedis of redis
随机推荐
Technology sharing swift defense programming
Redis source code analysis: redis cluster
[web Audit - source code disclosure] obtain source code methods and use tools
postman和postman interceptor的安装
How is the entered query SQL statement executed?
一文带你了解BI的前世今身与企业数字化转型的关系
Basic function learning 02
[untitled]
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 2)
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
【web审计-源码泄露】获取源码方法,利用工具
About the recent experience of writing questions
[positioning in JS]
UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
[software reverse - basic knowledge] analysis method, assembly instruction architecture
v-if VS v-show 2.0
On the day 25K joined Tencent, I cried
An elegant program for Euclid‘s algorithm
https://laravel-excel.com/