推荐导出组件chenvle/easy_excel

chenvle 2023-03-29 AM 1725℃ 7条

1、安装

composer require chenvle/easy_excel

2、使用例子

use Chenvle\EasyExcel\EasyExcel;
$excel = new Excel();
/*导入*/
$var   = [
    'A' => ['key' => 'username', 'title' => '姓名'],
    'B' => ['key' => 'phone', 'title' => '电话'],
    'C' => ['key' => 'origOrderId', 'title' => '订单号'],
    'D' => ['key' => 'txnAmt', 'title' => '订单金额'],
    'E' => ['key' => 'refundAmt', 'title' => '退款金额'],
    'F' => ['key' => 'remark', 'title' => '备注'],
];
$filepath = '***.xlsx';
// 1、excel表路径  2、每列对应数据键名及标题  3、内容开始的行
$excelData  = $excel->input($filepath, $var, 2);
/*导出*/
$field  = [
    'username'    => ['value' => '姓名', 'width' => '15', 'type' => 'string'],
    'school_str'  => ['value' => '学校', 'width' => '15', 'type' => 'string'],
    'grade'       => ['value' => '年级', 'width' => '10', 'type' => 'string'],
    'origOrderId' => ['value' => '订单号', 'width' => '25', 'type' => 'string'],
    'title'       => ['value' => '项目名称', 'width' => '30', 'type' => 'string', 'with' => 'orderInfo'],
    'phone'       => ['value' => '电话', 'width' => '15'],
    'txnAmt'      => ['value' => '订单金额', 'width' => '15'],
    'refundAmt'   => ['value' => '退款金额', 'width' => '15'],
    'status_str'  => ['value' => '状态', 'width' => '10', 'type' => 'string'],
    'remark'      => ['value' => '备注', 'width' => '15', 'type' => 'string'],
    'create_time' => ['value' => '下单时间', 'width' => '20', 'type' => 'string']
];
$str    = '待退款表';
$data = [];//导出的数据
//输出到浏览器
$excel->output($data, $str, $field,'Xlsx');

//保存到服务器返回路径(前面不用'/',后面也不用"/")
$url = $excel->output($data, $str, $field,'Xlsx','upload');
标签: none

非特殊说明,本博所有文章均为博主原创。

评论啦~



已有 7 条评论


  1. rlqvumkpha
    rlqvumkpha

    《地下特警》动作片高清在线免费观看:https://www.jgz518.com/xingkong/86566.html

    回复 2024-12-16 03:12
  2. hhkejymmdr
    hhkejymmdr

    真棒!

    回复 2024-11-20 08:11
    1. chenvle
      chenvle 博主

      谢谢

      回复 2024-11-26 22:44
  3. shijkooggg
    shijkooggg

    怎么收藏这篇文章?

    回复 2024-09-27 14:04
    1. chenvle
      chenvle 博主

      关注就可以了

      回复 2024-11-26 22:44
  4. wjvncdigyj
    wjvncdigyj

    博主真是太厉害了!!!

    回复 2024-09-22 18:59
    1. chenvle
      chenvle 博主

      谢谢

      回复 2024-11-26 22:44