//数组组完后生成excelvendor('Excel.PHPExcel');$objExcel = new PHPExcel();$objActSheet = $objExcel->getSheet(0);//设置打印纸张A4$objActSheet->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);//设置参数 $objActSheet->getColumnDimension('A')->setWidth(20);$objActSheet->getColumnDimension('B')->setWidth(20);$objActSheet->getColumnDimension('C')->setWidth(8);$objActSheet->getColumnDimension('D')->setWidth(50);$objActSheet->getColumnDimension('E')->setWidth(8);$objActSheet->getColumnDimension('F')->setWidth(8);$objActSheet->getColumnDimension('G')->setWidth(8);// 字体设置$objStyleA5 = $objActSheet->getStyle('A' . $i);$objFontA5 = $objStyleA5->getFont();$objFontA5->setName('宋体'); $objFontA5->setSize(10);//显示内容//A列 姓名$objActSheet->setCellValue('A1', '姓名');//B列 学期$objActSheet->setCellValue('B1', '学期'); //C列 学科$objActSheet->setCellValue('C1', '学科'); //D列 指标$objActSheet->setCellValue('D1', '指标');//E列 评级$objActSheet->setCellValue('E1', '评级');//F列 分数$objActSheet->setCellValue('F1', '分数'); $i = 2;foreach($report_list AS $k => $_xzv) {//A列 姓名$objActSheet->setCellValue('A' . $i, $_xzv['realname']); //B列 学期$objActSheet->setCellValue('B' . $i, $_xzv['report_term']); //C列 学科$objActSheet->setCellValue('C' . $i, $_xzv['subjectname']); //D列 指标$objActSheet->setCellValue('D' . $i, $_xzv['name']); //E列 评级$objActSheet->setCellValue('E' . $i, $_xzv['conf_name']); //F列 分数$objActSheet->setCellValue('F' . $i, $_xzv['sumstar']); $i++;}$objExcel->setActiveSheetIndex(0);//设置导出文件名 $fileName = 'studentReport.xlsx'; $xlsWriter = new PHPExcel_Writer_Excel2007($objExcel);header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');header("Content-Disposition: attachment; filename=\"$fileName\"");header('Cache-Control: max-age=0');$xlsWriter->save('php://output');exit;