当前位置:网站首页>laravel8 导出Excle文件
laravel8 导出Excle文件
2022-07-05 03:44:00 【s_罐装冰块】
1.参考Excle官方网址.
Laravel |中的 Superged Excel 导出和导入Laravel Excel (laravel-excel.com)https://laravel-excel.com/
2.使用composer命令来部署Excle。
composer require maatwebsite/excel
3.使用composer命令创建Excle导出模型。
php artisan make:export UsersExport --model=User
4.点击进入到我们刚刚创建的Excle控制器。
5.文件内容进行修改
注:如果我们导出excle表头的话,需要继承我们的表头文件。
在我们的控制中写入我们导出的方法即可:
最后通过路由调用我们的方法即可:
附上完整代码:
Excle模型文件内容:
<?php
namespace App\Exports;
use App\Models\AddlistModel;
use App\Models\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;//导出excle表头
class UsersExport implements FromCollection, WithHeadings
{
/**
* @return \Illuminate\Support\Collection
*/
public function collection()
{
//这里调用我们需要导出数据的模型
return AddlistModel::all();
}
//添加指定表头
public function headings(): array
{
return [
'ID',
'标题',
'文本',
'创建时间',
'修改时间'
];
}
}
控制器代码内容:
//导出我们Excl文件
public function export()
{
return Excel::download(new UsersExport, 'excle.xlsx');
}
边栏推荐
- error Couldn‘t find a package. JSON file in "your path“
- How to make the listbox scroll automatically when adding a new item- How can I have a ListBox auto-scroll when a new item is added?
- [an Xun cup 2019] not file upload
- glibc strlen 实现方式分析
- 为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
- How to learn to get the embedding matrix e # yyds dry goods inventory #
- postman和postman interceptor的安装
- Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation
- [groovy] string (string splicing | multi line string)
- A brief introduction to the behavior tree of unity AI
猜你喜欢
The new project Galaxy token just announced by coinlist is gal
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
Some enterprise interview questions of unity interview
error Couldn‘t find a package. JSON file in "your path“
花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
[wp][入门]刷弱类型题目
Easy processing of ten-year futures and stock market data -- Application of tdengine in Tongxinyuan fund
线上故障突突突?如何紧急诊断、排查与恢复
Clickhouse物化视图
A brief introduction to the behavior tree of unity AI
随机推荐
我就一写代码的,王总整天和我谈格局...
[安洵杯 2019]不是文件上传
英语必备词汇3400
Zero foundation uses paddlepaddle to build lenet-5 network
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
Kubernetes - identity and authority authentication
天干地支纪年法中为什么是60年一个轮回,而不是120年
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
Huawei MPLS experiment
DECLARE_ WAIT_ QUEUE_ HEAD、wake_ up_ Interruptible macro analysis
MindFusion. Virtual Keyboard for WPF
Kubernetes - identity and authority authentication
【看完就懂系列】一文6000字教你从0到1实现接口自动化
UI自动化测试从此告别手动下载浏览器驱动
线程基础知识
Unity implements the code of the attacked white flash (including shader)
Containerization Foundation
DMX parameter exploration of grandma2 onpc 3.1.2.5
[positioning in JS]
汇编-入门