dede织梦后台增加php导出到excel功能不出现乱码

,dede织梦系统怎样导出后台的文章或自定义模型中的数据到excel,并且不出现乱码,在后台目录创建一个php文件toexcel.php,在最上面加入代码;,require_once(dirname(__FILE__).'/config.php');,require_once(DEDEINC.'/typelink.class.php');,require_once(DEDEINC.'/datalistcp.class.php');,require_once(DEDEADMIN.'/inc/inc_list_functions.php');
 ,加入导出到excel类;,class Excel,{    ,  private $head;     ,private $body; ,  public function addHeader($arr){        ,  foreach($arr as $headVal){            ,$headVal = $this->charset($headVal);             ,$this->head .= "{$headVal} ";        ,}         ,$this->head .= " ";     ,} ,  public function addBody($arr){         ,  foreach($arr as $arrBody){             ,foreach($arrBody as $bodyVal){                 ,$bodyVal = $this->charset($bodyVal);                 ,$this->body .= "{$bodyVal} ";             ,}             ,$this->body .= " ";        ,}     ,} ,  public function downLoad($filename=''){         ,  if(!$filename)             ,  $filename = date('YmdHis',time()).'.xls';         ,  header("Content-type:application/vnd.ms-excel");         ,  header("Content-Disposition:attachment;filename=$filename");          ,  header("Content-Type:charset=gb2312");         ,  if($this->head)            ,  echo $this->head;         ,    echo $this->body;     ,} ,   public function charset($string){         ,return mb_convert_encoding($string,'GBK','auto');    ,   } ,} , ,代码解释:,1.输出列名数组,并转码,public function addHeader($arr){        ,  foreach($arr as $headVal){            ,$headVal = $this->charset($headVal);             ,$this->head .= "{$headVal} ";        ,}         ,$this->head .= " ";     ,} , ,2.输出导出内容数组,并转码,public function addBody($arr){         ,  foreach($arr as $arrBody){             ,foreach($arrBody as $bodyVal){                 ,$bodyVal = $this->charset($bodyVal);                 ,$this->body .= "{$bodyVal} ";             ,}             ,$this->body .= " ";        ,}     ,} 
 ,
返回顶部
跳到底部

Copyright 2011-2024 南京追名网络科技有限公司 苏ICP备2023031119号-6 乌徒帮 All Rights Reserved Powered by Z-BlogPHP Theme By open开发

请先 登录 再评论,若不是会员请先 注册