本身是用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::##// 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)