当前位置:网站首页>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/excel
3. Use composer Command to create Excle The export model .
php artisan make:export UsersExport --model=User
4. 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');
}
边栏推荐
- Some enterprise interview questions of unity interview
- Web components series (VII) -- life cycle of custom components
- Installation of postman and postman interceptor
- C语言课设:影院售票管理系统
- Assembly - getting started
- 汇编-入门
- [wp][introduction] brush weak type questions
- Special Edition: spreadjs v15.1 vs spreadjs v15.0
- DMX parameter exploration of grandma2 onpc 3.1.2.5
- Timing manager based on C #
猜你喜欢
Special Edition: spreadjs v15.1 vs spreadjs v15.0
[web source code code code audit method] audit skills and tools
Enterprise level: spire Office for . NET:Platinum|7.7. x
Clickhouse materialized view
Installation of postman and postman interceptor
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
Clickhouse物化视图
JVM garbage collection
JWT vulnerability recurrence
随机推荐
【软件逆向-分析工具】反汇编和反编译工具
BDF application - topology sequence
postman和postman interceptor的安装
provide/inject
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
[move pictures up, down, left and right through the keyboard in JS]
[web Audit - source code disclosure] obtain source code methods and use tools
Wechat applet development process (with mind map)
[untitled]
Technology sharing swift defense programming
Plasticscm enterprise crack
Quick start of UI component development of phantom engine [umg/slate]
Timing manager based on C #
lds链接的 顺序问题
Use of vscode software
Solve the problem that sqlyog does not have a schema Designer
speed or tempo in classical music
一文带你了解BI的前世今身与企业数字化转型的关系
Thread Basics
NEW:Devart dotConnect ADO.NET