admin_user.php
<?php
include 'PHPExcel.php';
include 'PHPExcel/Writer/Excel2007.php';
 $objPHPExcel = new PHPExcel();
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);$objWriter->save("resume.xls");$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);  
?>
在模版页面admin_user.html中
<!--IF($dc)-->
<!--$objPHPExcel = new PHPExcel();iconv('utf-8", "gb2312", $filename);
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save("resume.xls");
ob_clean();
$objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
Header('content-Type:application/vnd.ms-excel;charset=utf-8');
header("Pragma: public");
header("Expires: 0″);
header("Cache-Control:must-revalidate, post-check=0, pre-check=0″);
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header('Content-Disposition:attachment;filename="resume.xlsx"');
header("Content-Transfer-Encoding:binary");-->
<table cellpadding="0" cellspacing="1" class="list" id="tree_list" >
<tr>
<th width="7%">用户编号</th>
<th width="12%">用户名</th>
<th width="18%">EMAIL</th>
<th width="10%">注册时间</th>
<th width="10%">用户类型</th>
<th width="12%">最后登陆</th>
<th width="12%">登陆IP</th> </tr>
 <!--$userlist AS $v-->
    <tr align="center">     <td align="left" class="td1" style="text-align:center;"><span><a href="#">{v[uid]}</a></span></td>
     <td class="ud" >{v[username]}</td>
      <td class="od" >{v[email]}</td>
<td class="gd" >{run:}echo date('Y-m-d',$v[date_reg]){/run}</td>
<td class="td"><!--IF($v[usertype]==0)--><font color="green">普通用户</font><!--ELSEIF($v[usertype]==2)--><font color="green">套红人才</font><!--END--></td>
     <td>{run:}echo date('Y-m-d',$v[date_login]){/run}</td>
      <td>{v[iponline]}</td>
    
  </tr>
  <!--END-->
  </table><!--$objWriter->save('php://output');-->
<!--END-->
出现乱码,从来没做过导出excel,是不是程序不对?求解

解决方案 »

  1.   

    页面编码也要是gbk的
      

  2.   

    http://apps.hi.baidu.com/share/detail/22928518
      

  3.   

    header('Content-Type: application/vnd.ms-excel;charset=gb2312');
    在你填充的字段进行转码;
    $objActSheet -> setCellValue($key.'1', transformUtf8($_totaltitle[$value]));//列值
    //$objActSheet -> getColumnDimension($key) -> setWidth();//宽度
    $objActSheet -> getStyle($key.'1')       -> getAlignment() -> setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    $objActSheet -> setCellValue($key.($i+1), transformUtf8($ary[$i-1] -> $value));
    $objActSheet -> getStyle($key.($i+1))    -> getAlignment() -> setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);transformUtf8是一个自己手写的转码函数;function transformUtf8($str){
    if(!is_utf8($str)){
    return iconv("gbk","utf-8",$str);
    }
    return $str;
    }