当前位置:网站首页>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');
}
边栏推荐
- Uni app common functions /api
- Multimedia query
- JVM garbage collection
- MindFusion.Virtual Keyboard for WPF
- 函数基础学习02
- [learning notes] month end operation -gr/ir reorganization
- 请问一下我的请求是条件更新,但在buffer中就被拦截了,这种情况我只能每次去flush缓存么?
- [安洵杯 2019]不是文件上传
- NPM introduction link symbolic link
- Difference between MotionEvent. getRawX and MotionEvent. getX
猜你喜欢
Deep learning - LSTM Foundation
线上故障突突突?如何紧急诊断、排查与恢复
JWT漏洞复现
IronXL for . NET 2022.6
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
[positioning in JS]
Subversive cognition: what does SRE do?
About the recent experience of writing questions
@Transactional 注解导致跨库查询失效的问题
[an Xun cup 2019] not file upload
随机推荐
De debugging (set the main thread as hidden debugging to destroy the debugging Channel & debugger detection)
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
Nmap使用手册学习记录
Why is there a reincarnation of 60 years instead of 120 years in the tiangan dizhi chronology
天干地支纪年法中为什么是60年一个轮回,而不是120年
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
Deflocculant aminoiodotide eye drops
About authentication services (front and back, login, registration and exit, permission management)
Binary heap implementation (priority queue implementation)
Basic knowledge of tuples
Timing manager based on C #
[安洵杯 2019]不是文件上传
[learning notes] month end operation -gr/ir reorganization
Use Firefox browser to quickly pick up Web image materials
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
UI自动化测试从此告别手动下载浏览器驱动
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
[software reverse analysis tool] disassembly and decompilation tool