php-xlswriter Excel操作


function write($filename)
    {
        $config = ['path' => '/code/logs/'];
        $excel = new \Vtiful\Kernel\Excel($config);
        $header = [
            '訂單號',
            '業務類型',
            '公司id',
            '貸款銀行',
            '貸款銀行名字',
            '進單時間',
        ];

        $filePath = $excel->constMemory($filename)
            ->header($header);
        $bar = $this->output->createProgressBar(Trade::count('id') / 2000);
        $bar->setFormat("   %elapsed:6s%/%estimated:-6s%   內存消耗: %memory:6s%\n%current%/%max% [%bar%] %percent:3s%%");

//        // 讀取測試文件
//        $data = $excel->openFile('tutorial.xlsx')
//            ->openSheet();
//        $d = [];
//        while ($row = $excel->nextRow()) {
//            $this->info(json_encode($row, JSON_UNESCAPED_UNICODE));
//            $bar->advance();
//            $d[] = $row;
//        }
//        $bar->finish();
        Trade::orderBy('created_at')->chunk(2000, function ($trades) use ($filePath, $bar) {
            foreach ($trades as $trade) {
                $data[] = [
                    $trade->id,
                    $trade->product_type,
                    $trade->company_id,
                    $trade->admin_user_id,
                    $trade->loan_bank_code,
                    $trade->loan_bank_name,
                    $trade->created_at,
                ];
            }
            $filePath->data($data);
            $bar->advance();
        });
        $bar->finish();
        $filePath->output();
    }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM