phpexcel批量导出数据【用法说明】

phpexcel批量导出数据,主要参考代码段:

getProperties();
	//设置当前工作表
	$objExcel->setActiveSheetIndex(0);
	//获取当前工作表
	$objActSheet = $objExcel->getActiveSheet();
	//标题栏位置
	$columns = array(
		1 => "A", 
		2 => "B", 
		3 => "C", 
		4 => "D", 
		5 => "E", 
		6 => "F", 
		7 => "G", 
		8 => "H",
		9 => "I",
		10 => "J",
		11 => "K",
		12 => "L"
	);
	
	//标题栏名称
	$titles = array(
		1 => "姓名", 
		2 => "学号", 
		3 => "性别", 
		4 => "院系", 
		5 => "专业", 
		6 => "年级", 
		7 => "状态", 
		8 => "工作组", 
		9 => "综合评分",
		10 => "任务总数",
		11 => "完成数量",
		12 => "完成比例"
	);	
	//写入标题栏
	for($i=1;$i<=count($titles);$i++){
		$objActSheet->setCellValue($columns[$i] .'1', $titles[$i]);
	}
	$j = 1;
	foreach($result as $k=>$rs){
		$j++;
		$groupuser = array(
			1 => $rs["username"],
			2 => $rs["idnumber"],
			3 => $rs["year"],
			4 => $rs["year"],
			5 => $rs["year"],
			6 => $rs["year"],
			7 => $rs["year"],
			8 => $rs['title'],
			9 => $rs["year"],
			10 => $rs["doccount"],
			11 => $rs["number"],
			12 => $rs["prect"]
		);
		for($i=1;$i<=count($titles);$i++){
			if($i==2 || $i==12){
				$objActSheet->setCellValueExplicit($columns[$i] . $j, $groupuser[$i], PHPExcel_Cell_DataType::TYPE_STRING);
			}else{
				$objActSheet->setCellValue($columns[$i] . $j, $groupuser[$i]);
			}
			//设置字体
			$objStyle = $objActSheet->getStyle($columns[$i] . $j);
			$objFont = $objStyle->getFont();
		}
	}
	$objExcel->setActiveSheetIndex(0);
	$excelname = date("YmdHis");
	header('Content-Type: application/vnd.ms-excel; charset=utf-8');
	header('Content-Disposition: attachment;filename="'. $excelname .'.xls"');
	header('Cache-Control: max-age=0');
	$objWriter = PHPExcel_IOFactory::createWriter($objExcel, 'Excel5');
	$objWriter->save('php://output');//下载
	


你可能感兴趣的:(phpexcel)