首页 > 其他 > 详细

海量excel数据导出方案解决 xlswriter性能测试

时间:2021-05-29 12:15:05      阅读:15      评论:0      收藏:0      [点我收藏+]

2021年5月28日19:29:20

xlswriter 中文官方网站 https://xlswriter-docs.viest.me/zh-cn 

windows10 环境laravel8 mysql8 

 第一次执行会慢一点,第二次就更快一点,服务器上开了opcache估计会更快一点

public function test(Request $request)
    {
        $start_time = date(‘Y-m-d H:i:s‘);

        ini_set(‘memory_limit‘, ‘1024m‘);
        $config = [
            ‘path‘ => public_path() . ‘/upload‘ // xlsx文件保存路径
        ];
        $excel = new Excel($config);

        $textFile = $excel->fileName("free.xlsx")->header([‘id‘, ‘name‘, ‘phone‘, ‘source‘, ‘province_name‘, ‘city_name‘, ‘data_time‘, ‘user_id‘, ‘user_nickname‘, ‘register_time‘, ‘up_user_id‘, ‘store_name‘, ‘is_pull_new‘]);
        //大约11万数据
        foreach (BrokerMemberData::get() as $k => $v) {

            $textFile->insertText($k+1, 0, $v->id);
            $textFile->insertText($k+1, 1, $v->name);
            $textFile->insertText($k+1, 2, $v->phone);
            $textFile->insertText($k+1, 3, $v->source);
            $textFile->insertText($k+1, 4, $v->province_name);
            $textFile->insertText($k+1, 5, $v->city_name);
            $textFile->insertText($k+1, 6, $v->data_time);
            $textFile->insertText($k+1, 7, $v->user_id);
            $textFile->insertText($k+1, 8, $v->user_nickname);
            $textFile->insertText($k+1, 9, $v->register_time);
            $textFile->insertText($k+1, 10, $v->up_user_id);
            $textFile->insertText($k+1, 11, $v->store_name);
            $textFile->insertText($k+1, 12, $v->is_pull_new);
        }

        $filePath = $textFile->output();

        p(BrokerMemberData::count());
        p(‘执行成功 开始时间‘ . $start_time . ‘结束时间‘ . date(‘Y-m-d H:i:s‘));
        p($filePath);
    }

执行结果

115135
执行成功 开始时间2021-05-29 10:45:04结束时间2021-05-29 10:45:10
D:\phpstudy_pro\WWW\mc\public/upload/free.xlsx

性能还不错

 其他方案:

 

海量excel数据导出方案解决 xlswriter性能测试

原文:https://www.cnblogs.com/zx-admin/p/14823615.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!