企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
#样式链接 https://blog.csdn.net/gc258_2767_qq/article/details/81003656 ~~~ public function daochu() { set_time_limit(0); $data = $this->model->getList($this->request->param()); $spreadsheet = new Spreadsheet(); /* 设置默认文字居中 */ $styleArray = [ 'alignment' => [ 'horizontal' => 'center', 'vertical' => 'center', ], ]; $spreadsheet->getDefaultStyle()->applyFromArray($styleArray); $spreadsheet->getActiveSheet()->getRowDimension(1)->setRowHeight(30); $spreadsheet->getActiveSheet()->getDefaultRowDimension()->setRowHeight(20); $spreadsheet->getActiveSheet()->getColumnDimension('A')->setWidth(20); $spreadsheet->getActiveSheet()->getColumnDimension('B')->setWidth(30); $spreadsheet->getActiveSheet()->getColumnDimension('C')->setWidth(50); $spreadsheet->getActiveSheet()->getStyle('A')->getFont()->getColor()->setARGB('FFFF0000'); $spreadsheet->getActiveSheet()->getStyle('A1')->getFont()->getColor()->setARGB('FF000000'); $sheet = $spreadsheet->getActiveSheet(); $sheet->setCellValue('A1', 'id编号'); $sheet->setCellValue('B1', '订单编号'); $sheet->setCellValue('C1', '创建时间'); /*--------------开始从数据库提取信息插入Excel表中------------------*/ //$i=2; //定义一个i变量,目的是在循环输出数据是控制行数 /*$i = 2,因为第一行是表头,所以写到表格时候只能从第二行开始写。*/ $count = count($data); //计算有多少条数据 for ($i = 2; $i <= $count+1; $i++) { $sheet->setCellValue('A' . $i, $data[$i-2]['id']); $sheet->setCellValue('B' . $i, $data[$i-2]['order_no']); $sheet->setCellValue('C' . $i, $data[$i-2]['create_time']); } header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="'.'订单信息'.'.xlsx"'); header('Cache-Control: max-age=0');//禁止缓存 header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Expires: 0"); ob_clean(); ob_start(); $writer = new Xlsx($spreadsheet); $writer->save('php://output'); // 清除数据 $spreadsheet->disconnectWorksheets(); unset($spreadsheet); ob_flush(); flush();//必须同时使用 ob_flush() 和flush() 函数来刷新输出缓冲。 exit; } ~~~