找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2959|回复: 0

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

[复制链接]
发表于 2018-8-4 14:58:25 | 显示全部楼层 |阅读模式 来自 河南省新乡市
1、首先在后台修改/dede/templets/diy_main.htm

查看源码打印代码帮助
  1. <a href="../plus/diy.php?action=daochu&diyid={dede:field.diyid/}" target="_blank">导出为EXCEL</a>
复制代码


修改,后台效果如下图:
1.png


2、核心内容修改  plus/diy.php

  1. $action = isset($action) && in_array($action, array('post', 'list', 'view')) ? $action : 'post';
复制代码

替换成:


  1. $action = isset($action) && in_array($action, array('post', 'list', 'view', 'daochu')) ? $action : 'post';
复制代码

再在最后一行下面新加代码:

当然,下面输出表头的判断语句你可以自己改!


  1. else if($action == 'daochu')
  2. {
  3. header("Content-type:application/vnd.ms-excel");
  4. Header("Content-Disposition:attachment;filename={$diy->table}_".date("Y-m-d").".xls");  
  5. $query = "desc `{$diy->table}`";
  6. $res = mysql_query($query);
  7. echo "<table><tr>";
  8. //导出表头(也就是表中拥有的字段)
  9. while($row = mysql_fetch_array($res)){
  10.   $t_field[] = $row['Field']; //Field中的F要大写,否则没有结果
  11. /*   echo "<th>".$row['Field']."</th>"; */
  12.         if($row['Field']=='id'){
  13.             echo "<th>ID</th>";
  14.         }elseif($row['Field']=='zhaiwutype'){
  15.             echo "<th>债务类型</th>";
  16.         }elseif($row['Field']=='zhaiquanfang'){
  17.             echo "<th>债权方</th>";
  18.         }elseif($row['Field']=='name'){
  19.             echo "<th>名称</th>";
  20.         }elseif($row['Field']=='jigouhaoma'){
  21.             echo "<th>身份证号/机构代码</th>";
  22.         }elseif($row['Field']=='path'){
  23.             echo "<th>住址/地址</th>";
  24.         }elseif($row['Field']=='tel'){
  25.             echo "<th>联系电话</th>";
  26.         }elseif($row['Field']=='zhaiwufang'){
  27.             echo "<th>债务方</th>";
  28.         }elseif($row['Field']=='zhaiwufangname'){
  29.             echo "<th>债务方名称</th>";
  30.         }elseif($row['Field']=='zhaiwufanghaoma'){
  31.             echo "<th>债务方身份证号/机构代码</th>";
  32.         }elseif($row['Field']=='zhaiwufangpath'){
  33.             echo "<th>债务方地址</th>";
  34.         }elseif($row['Field']=='zhaiwufangtel'){
  35.             echo "<th>债务方电话</th>";
  36.         }elseif($row['Field']=='danbaofang1'){
  37.             echo "<th>担保方</th>";
  38.         }elseif($row['Field']=='danbao1name'){
  39.             echo "<th>担保方名称</th>";
  40.         }elseif($row['Field']=='danbao1haoma'){
  41.             echo "<th>身份证号/机构代码</th>";
  42.         }elseif($row['Field']=='danbao1tel'){
  43.             echo "<th>联系电话</th>";
  44.         }elseif($row['Field']=='zhaiwushuoming'){
  45.             echo "<th>债务说明</th>";
  46.         }elseif($row['Field']=='fayuanzhixing'){
  47.             echo "<th>法院是否强制执行</th>";
  48.         }elseif($row['Field']=='zhixingfayuan'){
  49.             echo "<th>执行法院</th>";
  50.         }elseif($row['Field']=='lianxiren'){
  51.             echo "<th>联系人</th>";
  52.         }elseif($row['Field']=='lianxidianhua'){
  53.             echo "<th>电话</th>";
  54.         }elseif($row['Field']=='zhaiwujine'){
  55.             echo "<th>债务金额</th>";
  56.         }elseif($row['Field']=='nativeplace1'){
  57.             echo "<th>住址/地址</th>";
  58.         }elseif($row['Field']=='jiamengtype'){
  59.             echo "<th>加入类型</th>";
  60.         }elseif($row['Field']=='groupname'){
  61.             echo "<th>公司(机构)名称</th>";
  62.         }elseif($row['Field']=='grouppath'){
  63.             echo "<th>公司地址</th>";
  64.         }elseif($row['Field']=='groupjianjie'){
  65.             echo "<th>公司简介</th>";
  66.         }elseif($row['Field']=='lianxiren'){
  67.             echo "<th>联系人</th>";
  68.         }elseif($row['Field']=='lianxitel'){
  69.             echo "<th>联系电话</th>";
  70.         }elseif($row['Field']=='lianximobile'){
  71.             echo "<th>手机</th>";
  72.         }elseif($row['Field']=='qq'){
  73.             echo "<th>QQ</th>";
  74.         }elseif($row['Field']=='name'){
  75.             echo "<th>姓名</th>";
  76.         }elseif($row['Field']=='xingbie'){
  77.             echo "<th>性别</th>";
  78.         }elseif($row['Field']=='nianling'){
  79.             echo "<th>年龄</th>";
  80.         }elseif($row['Field']=='danwei'){
  81.             echo "<th>工作单位</th>";
  82.         }elseif($row['Field']=='zhiwu'){
  83.             echo "<th>职务</th>";
  84.         }elseif($row['Field']=='dianhua'){
  85.             echo "<th>联系电话</th>";
  86.         }elseif($row['Field']=='mobile'){
  87.             echo "<th>手机</th>";
  88.         }elseif($row['Field']=='mail'){
  89.             echo "<th>E-mail</th>";
  90.         }elseif($row['Field']=='ifcheck'){
  91.             echo "<th>  </th>";
  92.         }else{
  93.             echo "<th>  </th>";
  94.         }
  95. }
  96. echo "</tr>";
  97. //导出数据
  98. $sql = "select * from `{$diy->table}`";
  99. $res = mysql_query($sql);
  100. while($row = mysql_fetch_array($res)){
  101.   echo "<tr>";
  102.     foreach($t_field as $f_key){
  103.         echo "<td>".$row[$f_key]."</td>";
  104.     }
  105.   echo "</tr>";
  106. }
  107. echo "</table>";
  108. }
复制代码


发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-3-29 15:48 , Processed in 0.041456 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表