织梦模板建站、织梦仿站,推荐选跟版网(专业织梦模板定制下载站),您可以把织梦模板网:加入收藏夹添加到桌面

收藏跟版网图片按钮
跟版网(www.genban.org)是专业的DEDECMS模板下载和定制开发服务商!
用户名: 密码: 验证码: 看不清?点击更换   注册帐号

跟版网-专业只为织梦模板

跟版网 > 织梦教程 > dedecms教程 > 一个DEDECMS自定义表单导出为excel功能的修改方法

一个DEDECMS自定义表单导出为excel功能的修改方法

作者:DEDECMS建站网 关注: 时间:2018-04-25 08:46

内容详情
1、首先在后台修改/dede/templets/diy_main.htm
 
<a href="../plus/diy.php?action=daochu&diyid={dede:field.diyid/}" target="_blank">导出为EXCEL</a>
 
修改,后台效果如下图:

 
2、核心内容修改  plus/diy.php
 
$action = isset($action) && in_array($action, array('post', 'list', 'view')) ? $action : 'post';
替换成:
 
$action = isset($action) && in_array($action, array('post', 'list', 'view', 'daochu')) ? $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>";
}

跟版网-专业织梦模板下载平台,转载请注明出处:http://www.genban.org/news/dedecms-19504.html

     邀您关注:  

扫描左侧二维码即可在手机端访问此页面

跟版网官方微信公众账号

扫描左侧二维码即可关注跟版网官方微信公众号,获取金币模板,还可以免费仿站哦!

跟版网官方QQ群

扫描左侧二维码即可加入跟版网官方群,免费获取金币资源并可以与其他织梦高手共同交流学习

跟版网率先实现织梦的三网合一网站,从即日起(2015-10-15)日,跟版网会陆续免费分享一批金币资源给需要的朋友,关注本站认证官方微信公众账号并回复相应的提取码,系统会自动将下载地址发送给您,同时这些金币资源也会分享在官方的QQ群中,欢迎各位朋友踊跃加入。另外本站后期会每周选择大家比较喜欢的网站仿制,并免费分享给大家,还有免费送金币活动哦!

上一篇:织梦dedecms自定义表单获取IP地址和提交时间

下一篇:织梦dedecms系统修改后台自定义表单列表为横排显示的办法