1、在織夢/dede/templets下面的member_main.htm,在全選按鈕那里添加一個導出excel按鈕;代碼如下:
<a href="toexcel.php" class="coolbg" target="_blank">導出到excel</a>
2、在織夢后臺dede文件夾下面新建toexcel.php;
toexcel.php的代碼如下:
<?phprequire_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');class Excel{private $head;private $body;//輸出列名數組,并轉碼public function addHeader($arr){foreach($arr as $headVal){$headVal = $this->charset($headVal);$this->head .= "{$headVal}\t ";}$this->head .= "\n";}//輸出導出內容數組public function addBody($arr){foreach($arr as $arrBody){foreach($arrBody as $bodyVal){//$bodyVal = $this->charset($bodyVal); (這個將信息內容轉碼的這句是不需要的,這個導出excel的代碼也是我百度的,但是測試的時候,導出的內容總是有部分的漢字是??的格式,找問題測試了半天發現其實這個內容是不需要轉碼的,直接導出就不會出現亂碼的格式了;據大神給我說的是看編碼,有的是需要轉碼的有的是不需要轉碼的)$this->body .= "{$bodyVal}\t ";}$this->body .= "\n";}}//設置header頭部信息和導出到excel內容,并輸出到瀏覽器public function downLoad($filename=''){if(!$filename)$filename = date('YmdHis',time()).'.xls';ob_end_clean();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;}//轉碼,這里不用iconv函數,有可能會與gd沖突導致輸出空白。用public function charset($string){return mb_convert_encoding($string,'GBK','auto');}}$excel = new Excel();$excel->addHeader(array('id','用戶類型','用戶帳號','密碼','用戶昵稱','性別','帳號有效期','級別','email','積分','添加時間','登錄時間','登錄IP'));global $dsql;$sql="select `mid`,`mtype`,`userid`,`pwd`,`uname`,`sex`,`exptime`,`rank`,`email`,`scores`,`jointime`,`logintime`,`loginip` from `dede_member`";$dsql->SetQuery($sql);$dsql->Execute();while($row = $dsql->GetArray()){//將添加時間和登錄時間轉化為2017 16:30 的格式,這樣在表格中更容易讓人懂,不這樣操作的話那么顯示出來的是Eforeach($row as $key=>$val){if($key=='jointime' || $key=='logintime'){$row[$key]=date("Y-m-d H:i:s",$val);}}$list[]=$row;}unset($row);$excel->addBody($list);$excel->downLoad();?>


