本人是用phpExcel导出会员表到浏览器,在线下测试正常,可以导出,也无编码错误,
1.线下正常导出的表格
2.线上导出有问题的表格
3,修改后缀后显示乱码
现贴出代码.
case 'test':
$data1 = MySql::fetchAll("SELECT real_name,telephone,car_id,regtime,endtime,sale,re_tel,type FROM `pw_member` where type=1");
$data2 = MySql::fetchAll("SELECT real_name,telephone,car_id,regtime,endtime,sale,re_tel,type FROM `pw_member` where type=2");
$data3 = MySql::fetchAll("SELECT real_name,telephone,car_id,regtime,endtime,sale,re_tel,type FROM `pw_member` where type=3");
//3种会员类型
foreach($data1 as $key=>&$val){
if($val['type']==1){
$val['type']='普通会员';
}
if($val['regtime']>58001){
$val['regtime']=date('Y-m-d',$val['regtime']);
}
if($val['endtime']>58001){
$val['endtime']=date('Y-m-d',$val['endtime']);
}
}
foreach($data2 as $key=>&$val){
if($val['type']==2){
$val['type']='VIP会员';
}
if($val['regtime']>58001){
$val['regtime']=date('Y-m-d',$val['regtime']);
}
if($val['endtime']>58001){
$val['endtime']=date('Y-m-d',$val['endtime']);
}
}
foreach($data3 as $key=>&$val){
if($val['type']==3){
$val['type']='金卡会员';
}
if($val['regtime']>58001){
$val['regtime']=date('Y-m-d',$val['regtime']);
}
if($val['endtime']>58001){
$val['endtime']=date('Y-m-d',$val['endtime']);
}
}
// Cxt::dump($data1);
$a=array(
0=>'真实姓名',
1=>'电话号码',
2=>'车牌号',
3=>'注册日期',
4=>'到期时间',
5=>'推荐人',
6=>'推荐人电话',
7=>'会员类型',
);
array_unshift($data1,$a); //加入表头
array_unshift($data2,$a); //加入表头
array_unshift($data3,$a); //加入表头
$data[1]=$data1;
$data[2]=$data2;
$data[3]=$data3;
require('./include/PHPExcel/PHPExcel.php');
// require dirname(__FILE__).'/PHPExcel/PHPExcel.php';
$objPHPExcel = new PHPExcel();//实例化phpexcel类
// Cxt::dump($objPHPExcel);
for($i=1;$i<=3;$i++){
if($i>1){
$objPHPExcel->createSheet();//创建新的内置表
$objPHPExcel->setActiveSheetIndex($i-1);//把新创建的sheet设置为当前活动的sheet
}
$objSheet=$objPHPExcel->getActiveSheet();//获取当前活动sheet
$objSheet->setTitle($i.'会员');
$objSheet->fromArray($data[$i]);
}
$objWriter=PHPExcel_IOFactory::createWriter($objPHPExcel,'Excel2007');
$name=date('Y-m-d',time()).time();
$name='member'.$name.'.xlsx';
// $objWriter->save($name);//保存到服务器
// header('Content-Type: application/vnd.ms-excel');//告诉浏览器将要输出2003文件
header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8');
header('Content-Disposition: attachment;filename='."$name");//告诉浏览器将输出文件的名称
header('Cache-Control: max-age=0');
$objWriter->save("php://output");
break;
有遇到这种问题的希望给小弟指导下,感激不尽...
I Know H.T.M.L(How to Meet Ladies)