当前位置:网站首页>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');
}
边栏推荐
- Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
- @Transactional 注解导致跨库查询失效的问题
- C语言课设:影院售票管理系统
- Rust区块琏开发——签名加密与私钥公钥
- KVM virtualization
- This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
- How rem is used
- [web source code code code audit method] audit skills and tools
- 在线文本行固定长度填充工具
- NEW:Devart dotConnect ADO.NET
猜你喜欢
Containerd series - what is containerd?
【软件逆向-基础知识】分析方法、汇编指令体系结构
Thread Basics
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
What is test development? Why do so many companies hire test developers now?
DMX parameter exploration of grandma2 onpc 3.1.2.5
UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程
[wp][入门]刷弱类型题目
How to define a unified response object gracefully
Redis source code analysis: redis cluster
随机推荐
The new project Galaxy token just announced by coinlist is gal
postman和postman interceptor的安装
25K 入职腾讯的那天,我特么哭了
Unity implements the code of the attacked white flash (including shader)
This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
线上故障突突突?如何紧急诊断、排查与恢复
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
已解决(sqlalchemy+pandas.read_sql)AttributeError: ‘Engine‘ object has no attribute ‘execution_options‘
Plasticscm enterprise crack
【PHP特性-变量覆盖】函数的使用不当、配置不当、代码逻辑漏洞
天干地支纪年法中为什么是60年一个轮回,而不是120年
NPM introduction link symbolic link
Containerization Foundation
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
An elegant program for Euclid‘s algorithm
【web審計-源碼泄露】獲取源碼方法,利用工具
speed or tempo in classical music
error Couldn‘t find a package. JSON file in "your path“
DMX parameter exploration of grandma2 onpc 3.1.2.5
Web components series (VII) -- life cycle of custom components