exportExcel.php 'select ID,Username,Email,name,Classid,Logintime,phone from ljst_user where Roleid=9','student'='select ID,Username,Email,name,Classid,Logintime,phone from ljst_user where Roleid=10','other'='select ID,Username,Email,name,Cl
'select ID,Username,Email,name,Classid,Logintime,phone from ljst_user where Roleid=9','student'=>'select ID,Username,Email,name,Classid,Logintime,phone from ljst_user where Roleid=10','other'=>'select ID,Username,Email,name,Classid,Logintime,phone from ljst_user where Roleid<>10 and Roleid<>9');
$objPHPExcel = new PHPExcel();
for($i=0;$i<3;$i++){
if($i>0){
$objPHPExcel->createSheet();//创建新的sheet
}
$objPHPExcel->setActiveSheetIndex($i);
$objSheet=$objPHPExcel->getActiveSheet();
if($i==0){
$objSheet->setTitle('teacher');
$res = $DB->query($sqlarr['teacher']);
}elseif($i==1){
$objSheet->setTitle('student');
$res = $DB->query($sqlarr['student']);
}elseif($i==2){
$objSheet->setTitle('other');
$res = $DB->query($sqlarr['other']);
}
$objSheet->fromArray($res);
}
//第一种输出到目标位置
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,"Excel5");
/*
$objWriter->save($dir.'/File/'.$name.'.xlsx');*/
//输出到浏览器 第二种输出到浏览器
//定义头信息
function browser_export($type,$filename){
if($type=='Excel5'){
header('Content-Type:application/vnd:ms-excel');
}else{
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
}
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header ('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); // always modified
header ('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header ('Pragma: public'); // HTTP/1.0
header('Content-Disposition: attachment;filename="'.$filename.'"');
}
//输出到浏览器
browser_export('Excel5',$name.'.xlsx');
$objWriter->save('php://output');
//关闭链接
$DB->destruct();
?>
