导出excel
// 导出excel
require_once('PHPExcel.php');
require_once('PHPExcel/IOFactory.php');
$objPHPExcel=new PHPExcel();
$iofactory=new PHPExcel_IOFactory();
// 组织数据
$data=array(
1=>array('NAME'=>'小王','SEX'=>'男','AGE'=>'15','ADRESS'=>'江苏南京','SCHOOL'=>'南京中学','CLASS'=>'1班','TEL'=>'12345678901'),
2=>array('NAME'=>'小李','SEX'=>'女','AGE'=>'12','ADRESS'=>'江苏徐州','SCHOOL'=>'贾汪中学','CLASS'=>'3班','TEL'=>'12345678901'),
3=>array('NAME'=>'刘能','SEX'=>'男','AGE'=>'15','ADRESS'=>'江苏南京','SCHOOL'=>'南京中学','CLASS'=>'1班','TEL'=>'12345678901'),
4=>array('NAME'=>'赵四','SEX'=>'男','AGE'=>'15','ADRESS'=>'江苏南京','SCHOOL'=>'南京中学','CLASS'=>'1班','TEL'=>'12345678901'),
5=>array('NAME'=>'小谢','SEX'=>'男','AGE'=>'15','ADRESS'=>'江苏南京','SCHOOL'=>'南京中学','CLASS'=>'1班','TEL'=>'12345678901'),
6=>array('NAME'=>'王老七','SEX'=>'男','AGE'=>'15','ADRESS'=>'江苏南京','SCHOOL'=>'南京中学','CLASS'=>'1班','TEL'=>'12345678901')
);
//设置excel列名
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1','姓名');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B1','性别');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C1','年龄');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D1','家庭住址');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('E1','学校');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('F1','班级');
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('G1','电话');
//把数据循环写入excel中
foreach($data as $key => $value){
$key+=1;
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value['NAME']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value['SEX']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$value['AGE']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$key,$value['ADRESS']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('E'.$key,$value['SCHOOL']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('F'.$key,$value['CLASS']);
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('G'.$key,$value['TEL']);
}