🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
``` ob_end_clean(); $columns=[ ['month', '月份'], ['acontract_nums', '当月下达合同(协议)数量'], ['production_nums', '月下达产量(吨)'], ['xian_xiada', "西安公司"], ['shandong_xiada', "山东公司"], ['not_acontract_nums', "合同数量"], ['not_production_nums', "待下达量"], ['not_xian_xiada', "西安公司"], ['not_shandong_xiada', "山东公司"], ['year_on_year_growth', "同比增长"], ]; $heji['month']="合计"; $heji['acontract_nums']= ""; $heji['production_nums']= ""; $heji['xian_xiada']= ""; $heji['shandong_xiada']= ""; $heji['not_acontract_nums']= ""; $heji['not_production_nums']= ""; $heji['not_xian_xiada']= ""; $heji['not_shandong_xiada']= ""; $heji['year_on_year_growth']=""; $data[]=$heji; $list['total']=count($data); $list['data']=$data; // 初始化表头数组 $str = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); // foreach ($columns as $k => $v) { // $sheet->setCellValue($str[$k] . '1', $v['1']); // } // $sheet->setCellValue('B1','其中:当月下达')->mergeCells('B1:E1'); $sheet->setCellValue('F1','待下达')->mergeCells('F1:I1'); $sheet->setCellValue('A1','月份')->mergeCells('A1:A2'); $sheet->setCellValue('B2','当月下达合同(协议)数量'); $sheet->setCellValue('C2','月下达产量(吨)'); $sheet->setCellValue('D2','西安公司'); $sheet->setCellValue('E2','山东公司'); $sheet->setCellValue('F2','待下达合同数量'); $sheet->setCellValue('G2','待下达量'); $sheet->setCellValue('H2','西安公司'); $sheet->setCellValue('I2','山东公司'); $sheet->setCellValue('J1','同比增长')->mergeCells('J1:J2'); $list = (isset($list['total']) && isset($list['per_page']) && isset($list['data'])||isset($list['total'])) ? $list['data'] : $list; foreach ($list as $key => $value) { foreach ($columns as $k => $v) { $sheet->setCellValue($str[$k] . ($key + 3), $value[$v['0']]); } } $name ="xxx报表"; header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="' . $name . '导出' . '.xlsx"'); header('Cache-Control: max-age=0'); $writer = new Xlsx($spreadsheet); $writer->save('php://output');//输出文件标题 ``` ![](https://img.kancloud.cn/1c/51/1c51b675568765dee5409dbeb223742c_694x152.png)