当前位置:网站首页>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');
}边栏推荐
- 【看完就懂系列】一文6000字教你从0到1实现接口自动化
- 【web审计-源码泄露】获取源码方法,利用工具
- JWT vulnerability recurrence
- Pyqt pyside custom telescopic menu bar sharing (including tutorial)
- [move pictures up, down, left and right through the keyboard in JS]
- [wp]bmzclub几道题的writeup
- UI自动化测试从此告别手动下载浏览器驱动
- provide/inject
- 优先使用对象组合,而不是类继承
- IronXL for .NET 2022.6
猜你喜欢

How to use jedis of redis

10种寻址方式之间的区别

函数基础学习02

企业级:Spire.Office for .NET:Platinum|7.7.x

It took two nights to get Wu Enda's machine learning course certificate from Stanford University

Containerd series - what is containerd?

Thread Basics

我就一写代码的,王总整天和我谈格局...

Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5

深度学习——LSTM基础
随机推荐
企业级:Spire.Office for .NET:Platinum|7.7.x
Assembly - getting started
英语必备词汇3400
laravel8 导出Excle文件
About authentication services (front and back, login, registration and exit, permission management)
[brush questions] BFS topic selection
Deep learning - LSTM Foundation
v-if VS v-show 2.0
[web source code code code audit method] audit skills and tools
[web Audit - source code disclosure] obtain source code methods and use tools
Nmap使用手册学习记录
Clickhouse同步mysql(基于物化引擎)
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
[vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils
Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
已解决(sqlalchemy+pandas.read_sql)AttributeError: ‘Engine‘ object has no attribute ‘execution_options‘
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
https://laravel-excel.com/