dede织梦cms后台管理提升php导出来到excel作用出不
时间: 2021-02-23 14:02
浏览次数:
在后台管理文件目录建立一个php文档toexcel.php,在最上边添加编码;require_once(dirname(__FILE__). /config.php require_once(DEDEINC. /typelink.class.php require_once(DEDEINC. /datalistcp.class.php require_once(DEDEADMIN.
在后台管理文件目录建立一个php文档toexcel.php,在最上边添加编码;
require_once(dirname(__FILE__). /config.php
require_once(DEDEINC. /typelink.class.php
require_once(DEDEINC. /datalistcp.class.php
require_once(DEDEADMIN. /
添加导出来到excel类;
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);
$this- body .= {$bodyVal}\t
}
$this- body .= \n
}
}
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}\t
}
$this- head .= \n
}
2.輸出导出来內容数字能量数组,并转换格式
public function addBody($arr){
foreach($arr as $arrBody){
foreach($arrBody as $bodyVal){
$bodyVal = $this- charset($bodyVal);
$this- body .= {$bodyVal}\t
}
$this- body .= \n
}
}
3.设定header头顶部信息内容和导出来到excel內容,并輸出到访问器
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;
}
4.转换格式,这儿无需iconv涵数,有将会会与gd矛盾造成輸出空白页。用
public function charset($string){
return mb_convert_encoding($string, GBK , auto
}
7.启用方式;
$excel = new Excel();
$excel- addHeader(array( 列一 , 列二 , 列三 , 列四
global $dsql;
$sql= select 列一字段名,列二字段名,列三字段名,列四字段名 from 表名
$dsql- SetQuery($sql);
$dsql- Execute();
while($row = $dsql- GetArray()){
$list[]=$row;
}
unset($row);
$excel- addBody($list);
$excel- downLoad();
后天加上导出来到excel编码:
寻找后台管理文件目录下的templets文件目录,下边有一个content_list.htm文档,
寻找 a href= javascript:; quot;cAtts( attsDel ,event,this) >
在后边加一段编码
?php if($channelid==1) echo a href=\ toexcel.php\ >
$channelid便是你的实体模型id,依据你导出来的表填好。填好完以后开启后台管理频道目录就出現导出来按键
dedecms模版,dedecms公司模版,dedecms新闻资讯模版,高档HTML5响应式模版,dedecms手机上模版,织梦cms模版实例教程,网站模版,网页页面模版,完全免费网页页面模版