ThinkPHP5实现导出Excel

浏览:2505 发布日期:2018/12/28 分类:功能实现 关键字: PHPExcel 导出Excel
ThinkPHP5实现导出Excel

阿里云搞活动,想要抓紧买:https://promotion.aliyun.com/ntms/act/qwbk.html?userCode=4hy76kwx

很多时候,我们需要用到导出Excel的功能,PHPExcel是一个很好的导出Excel的插件,今天分享一下ThinkPHP5利用PHPExcel实现导出Excel。

控制器代码: public function index()
    {
        return $this->fetch();
    }

    //导出Excel表格
    public function daochu(){
        //导出Excel表格
        $expTitle = '导出测试';

        //表头
        $expCellName = [];
        $expCellName[] = ['id','ID'];
        $expCellName[] = ['name','姓名'];
        $expCellName[] = ['shouji','手机'];
        $expCellName[] = ['qq','QQ'];
        $expCellName[] = ['weixin','微信'];

        //导出数据,实际数据可以是从mysql导出
        $data = [];
        $data[] = ['id'=>1,'name'=>'张三','shouji'=>'15098881234','qq'=>'\'947803117','weixin'=>'zouseu'];
        $data[] = ['id'=>2,'name'=>'李四','shouji'=>'15098881234','qq'=>'\'947803117','weixin'=>'zouseu'];


        $expTableData = $data;

        exportExcel($expTitle, $expCellName, $expTableData);
    }
模板代码<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>导出Excel</title>
</head>
<body>
<input type="button" onclick="window.location.href='{:url('daochu')}'" value="导出Excel">
</body>
</html>
如果需要代码,请加群:282882201,在群文件中下载

阿里云搞活动,想要抓紧买:https://promotion.aliyun.com/ntms/act/qwbk.html?userCode=4hy76kwx
评论( 相关
后面还有条评论,点击查看>>