Laravel框架Excel数据导入导出

本文介绍了在Laravel框架中如何实现Excel数据的导入导出,包括导出数据为数组和txt文件,以及将数据导出为Excel文件。同时,也展示了在TP5框架中如何进行Excel数据的导入,包括文件验证、数据读取和入库操作。
摘要由CSDN通过智能技术生成

一、laravel框架

(1)Excel数据导出为数组

$path_all1 = '/data/user_data.xlsx';

if (!file_exists($path_all1)) {

return $this->fail('文件不存在');

}

$now = date('Y-m-d H:i:s');

$data1 = [];

Excel::load($path_all1, function ($reader) use (&$data1) {

$reader = $reader->getSheet(0);

$data1 = $reader->toArray();

});

(2)Excel数据导出为txt文件

if (count($result) > 0) {

$result = json_encode($result, JSON_UNESCAPED_UNICODE);

file_put_contents('/mnt/vdc/groupInfo.txt', $result);

}

(3)将数据导出为Excel文件

$excel_name = 'deposits_05_1';

 $info = Excel::create($excel_name, function ($excel) use ($orders) {

 $excel->sheet('deposits', function ($sheet) use ($orders) {

 $sheet->rows($orders);

 });

 })->store('xlsx');

二、tp5的Excel导入

public function load(){

$controller = $this->request->controller();

if ($this->request->isAjax()){

$file = $this->request->post(false);

$file = $this->req

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值