🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` composer require phpoffice/phpexcel ``` ``` use PHPExcel_IOFactory; use PHPExcel; //会员资料导出 public function excel(){ $PHPExcel = new PHPExcel();//实例化 for($i=1;$i<=3;$i++){ $PHPSheet = $PHPExcel->getActiveSheet(); $PHPSheet->setTitle("demo"); //给当前活动sheet设置名称 $data=Db::table('user')->select(); $PHPSheet->setCellValue("A1","用户id")->setCellValue("B1","账号")->setCellValue("C1","openId")->setCellValue("D1","状态")->setCellValue("E1","注册时间");//表格数据 $i==2; foreach($data as $key=>$val){ $PHPSheet->setCellValue("A".$i,$val['user_id'])->setCellValue("B".$i,$val['account'])->setCellValue("C".$i,$val['openid'])->setCellValue("D".$i,$val['sys_status'])->setCellValue("E".$i,$val['create_time']);//表格数据 $i++; } } ob_end_clean(); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="会员.xls" '); header('Cache-Control: max-age=1'); header("Content-type: text/html; charset=utf-8"); $PHPWriter = PHPExcel_IOFactory::createWriter($PHPExcel,"Excel2007");//创建生成的格式 $PHPWriter->save("php://output"); //表示输出到浏览器 } ```