当前位置:网站首页>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/excel3.使用composer命令创建Excle导出模型。
php artisan make:export UsersExport --model=User4.点击进入到我们刚刚创建的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');
}边栏推荐
- KVM virtualization
- v-if VS v-show 2.0
- @Transactional 注解导致跨库查询失效的问题
- How about programmers' eyesight| Daily anecdotes
- Kubernetes - identity and authority authentication
- A brief introduction to the behavior tree of unity AI
- MindFusion.Virtual Keyboard for WPF
- 花了2晚,拿到了吴恩达@斯坦福大学的机器学习课程证书
- Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
- Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation
猜你喜欢

An elegant program for Euclid‘s algorithm
![[learning notes] month end operation -gr/ir reorganization](/img/4e/9585b7c62527beaa30a74060cb0e94.jpg)
[learning notes] month end operation -gr/ir reorganization

Yyds dry goods inventory embedded matrix

C # use awaiter

Basic function learning 02

KVM virtualization

程序员的视力怎么样? | 每日趣闻

Multimedia query

Easy processing of ten-year futures and stock market data -- Application of tdengine in Tongxinyuan fund

【web源码-代码审计方法】审计技巧及审计工具
随机推荐
面试汇总:这是一份全面&详细的Android面试指南
Assembly - getting started
Delphi free memory
输入的查询SQL语句,是如何执行的?
Redis之Jedis如何使用
English essential vocabulary 3400
[数组]566. 重塑矩阵-简单
Enterprise level: spire Office for . NET:Platinum|7.7. x
[wp][入门]刷弱类型题目
Why is there a reincarnation of 60 years instead of 120 years in the tiangan dizhi chronology
Monitoring web performance with performance
官宣!第三届云原生编程挑战赛正式启动!
How rem is used
[groovy] string (string splicing | multi line string)
grandMA2 onPC 3.1.2.5的DMX参数摸索
New interesting test applet source code_ Test available
IronXL for .NET 2022.6
KVM virtualization
Plasticscm enterprise crack
【软件逆向-分析工具】反汇编和反编译工具