当前位置: 首页 > 织梦二次开发教程 > 织梦dedecms自定义表单数据批量导出到excel的开发方法

帮助中心

当前位置: 首页 > 织梦二次开发教程 > 织梦dedecms自定义表单数据批量导出到excel的开发方法

织梦dedecms自定义表单数据批量导出到excel的开发方法

织梦猫(dedemao.cn) /   如有任何问题,也可咨询猫哥QQ:969969429
[] [] []

 

    最近开发了一个利用织梦自定义表单进行报名的报名系统。报名数量比较多。后台管理不是很方便。就需要把所有报名数据全部导出,并形成excel表格。方便管理与统计。

   

开发方法如下:

第一步:打开/dede/templets/diy_main.htm,增加导出按钮,如上图所示。找到前台预览,在其后增加如下代码:

 <a href="../plus/diy.php?action=daochu&amp;diyid={dede:field.diyid/}" target="_blank">导出为EXCEL</a>

第二步:打开/plus/diy.php,找到如下代码

 $action = isset($action) && in_array($action, array('post', 'list', 'view')) ? $action : 'post';

 第三步:再在最后一行下面新加代码,温馨提醒,具体的表头和字段都是需要根据您自己的进行修改调整:

 else if($action == 'daochu')
{
header("Content-type:application/vnd.ms-excel");
Header("Content-Disposition:attachment;filename={$diy->table}_".date("Y-m-d").".xls");
$query = "desc `{$diy->table}`";
$res = mysql_query($query);
echo "<table><tr>";
//导出表头(也就是表中拥有的字段)
while($row = mysql_fetch_array($res)){
$t_field[] = $row['Field']; //Field中的F要大写,否则没有结果
/* echo "<th>".$row['Field']."</th>"; */
if($row['Field']=='id'){
echo "<th>ID</th>";
}elseif($row['Field']=='zhaiwutype'){
echo "<th>债务类型</th>";
}elseif($row['Field']=='zhaiquanfang'){
echo "<th>债权方</th>";
}elseif($row['Field']=='name'){
echo "<th>名称</th>";
}elseif($row['Field']=='jigouhaoma'){
echo "<th>身份证号/机构代码</th>";
}elseif($row['Field']=='path'){
echo "<th>住址/地址</th>";
}elseif($row['Field']=='tel'){
echo "<th>联系电话</th>";
}elseif($row['Field']=='zhaiwufang'){
echo "<th>债务方</th>";
}elseif($row['Field']=='zhaiwufangname'){
echo "<th>债务方名称</th>";
}elseif($row['Field']=='zhaiwufanghaoma'){
echo "<th>债务方身份证号/机构代码</th>";
}elseif($row['Field']=='zhaiwufangpath'){
echo "<th>债务方地址</th>";
}elseif($row['Field']=='zhaiwufangtel'){
echo "<th>债务方电话</th>";
}elseif($row['Field']=='danbaofang1'){
echo "<th>担保方</th>";
}elseif($row['Field']=='danbao1name'){
echo "<th>担保方名称</th>";
}elseif($row['Field']=='danbao1haoma'){
echo "<th>身份证号/机构代码</th>";
}elseif($row['Field']=='danbao1tel'){
echo "<th>联系电话</th>";
}elseif($row['Field']=='zhaiwushuoming'){
echo "<th>债务说明</th>";
}elseif($row['Field']=='fayuanzhixing'){
echo "<th>法院是否强制执行</th>";
}elseif($row['Field']=='zhixingfayuan'){
echo "<th>执行法院</th>";
}elseif($row['Field']=='lianxiren'){
echo "<th>联系人</th>";
}elseif($row['Field']=='lianxidianhua'){
echo "<th>电话</th>";
}elseif($row['Field']=='zhaiwujine'){
echo "<th>债务金额</th>";
}elseif($row['Field']=='nativeplace1'){
echo "<th>住址/地址</th>";
}elseif($row['Field']=='jiamengtype'){
echo "<th>加入类型</th>";
}elseif($row['Field']=='groupname'){
echo "<th>公司(机构)名称</th>";
}elseif($row['Field']=='grouppath'){
echo "<th>公司地址</th>";
}elseif($row['Field']=='groupjianjie'){
echo "<th>公司简介</th>";
}elseif($row['Field']=='lianxiren'){
echo "<th>联系人</th>";
}elseif($row['Field']=='lianxitel'){
echo "<th>联系电话</th>";
}elseif($row['Field']=='lianximobile'){
echo "<th>手机</th>";
}elseif($row['Field']=='qq'){
echo "<th>QQ</th>";
}elseif($row['Field']=='name'){
echo "<th>姓名</th>";
}elseif($row['Field']=='xingbie'){
echo "<th>性别</th>";
}elseif($row['Field']=='nianling'){
echo "<th>年龄</th>";
}elseif($row['Field']=='danwei'){
echo "<th>工作单位</th>";
}elseif($row['Field']=='zhiwu'){
echo "<th>职务</th>";
}elseif($row['Field']=='dianhua'){
echo "<th>联系电话</th>";
}elseif($row['Field']=='mobile'){
echo "<th>手机</th>";
}elseif($row['Field']=='mail'){
echo "<th>E-mail</th>";
}elseif($row['Field']=='ifcheck'){
echo "<th> </th>";
}else{
echo "<th> </th>";
}
}
echo "</tr>";
//导出数据
$sql = "select * from `{$diy->table}`";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)){
echo "<tr>";
foreach($t_field as $f_key){
echo "<td>".$row[$f_key]."</td>";
}
echo "</tr>";
}
echo "</table>";
}

 开发完成

 温馨提示:以上问题还是没解决的,请联系本站客服。。本站站长 诚收织梦仿站高徒 ,3天打造仿站高手,没有仿不了的展示站。需要的请与客服联系。

骚扰客服

请关注织梦猫微信