Box/Spout 循环导出
<?php $tmpFile = tmpfile(); # 创建临时文件 $meta = stream_get_meta_data($tmpFile); $writer = ExcelWriter::newWriter($meta['uri']); # 等于最下方类 $writer->addHeader([ 'unionid', '真实姓名', '手机号' ], 11); //获取数据【批次获取 每次获取N条 并写入】 $maxId = 0; while (true) { //获取一批数据 $resp = AgentNumberOfDoctorRepository::AgentNumberOfDoctorsDetail( $nickname, $truename,
$maxId, 50 ); if (!$resp) { break; }
//构建数据集合 foreach ($resp as $key => $value) { $data[$key]['unionid'] = $value['unionid']; $data[$key]['nickname'] = $value['nickname']; $data[$key]['share_phone_number'] = $value['share_phone_number'] ?? ''; } # 循环写入 $tmpRows = []; foreach ($rows as $row) { $tmpRows[] = WriterEntityFactory::createRowFromArray($row); } $this->writer->addRows($tmpRows); //循环游标起始位置 foreach ($resp as $item) { $maxId = max($maxId, item['id']); } }
$writer->close(); fseek($tmpFile, 0, SEEK_END); $end = ftell($tmpFile); fseek($tmpFile, 0, SEEK_SET);
# 这里保存文件,目前采用文件上传七牛,再把接收到的地址存表。 其他人自便 直接存自己服务器都可以
$writer = WriterEntityFactory::createXLSXWriter(); $writer->openToFile($filePath); /** Create a style with the StyleBuilder */ $style = (new StyleBuilder()) ->setFontBold() ->setFontSize(15) ->setFontColor(Color::BLUE) ->setShouldWrapText() ->setCellAlignment(CellAlignment::RIGHT) ->setBackgroundColor(Color::YELLOW) ->build();
# 官网地址:opensource.box.com
作者地址:https://www.cnblogs.com/G921123/
创作也有乐趣 知识分享 转载注明出处 相互理解 谢谢!
创作也有乐趣 知识分享 转载注明出处 相互理解 谢谢!