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

1、首先在后台修改/dede/templets/diy_main.htm a href=../plus/diy.php?action=daochudiyid={dede:field.diyid/} target=_blank导出为EXCEL/a 修改,后台效果如下图: 2、核心内容修改 plus/diy.php $action = isset($action) in_array($action, array(post
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>";
}

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

dedecms织梦默认的TAG标签不是很灵活。有时候我们的标签需要进行一个分类,能不能像{dede:arclist}标签的自定义属性(如:flag=c,h),这样全站调用的时候更灵活。 全站调用TAG标签方法一般是: {dede:tag row='100' sort='new' getall='1'}a target="_blank
未审核文档的TAG会显示在TAG列表页面, 固然点击进入TAG时, 相关的未审核文章不会显示出来, 这样对用户体验是很不好的. DEDECMS暂时没有提供这个功能,所以要解决这个问题, 让DEDECMS不显示未审核文档的TAG, 就要修改TAG的显示库文件 tag.lib.php。 方法一 打
我们都知道DEDECMS生成的文件夹是按天生成的,只要传了图片就会自动建立个年月日的文件,centos系统下,都是随便排序的,很难找到对应文件夹,如果要按顺序排列,要怎么操作呢? 一、文件管理器: 修改 /dede/templets/file_manage_main.html $dh = dir($inp
我们在用到织梦dedecms软件模型的时候,手动指定地址通常只能是引用其他网址或者链接,我们要实现直接选取站内的文件,这个要怎么操作呢?下面小编一步步为您解答,最终效果如下图所示: 实现教程 1、打开 /dede/templets/soft_add.htm 找到 input type=text
我们有时候需要对织梦文档的点击量进行批量维护,比如采集来的文章,点击量都为0,需要批量修改,可以用到如下方法1。 1、在数据库里运行下面的代码就可以了,文章的点击量变得随机从500到1000 UPDATE dede_archives SET click=FLOOR(500 + (RAND() * 1000))
用过dedecms的朋友都知道,织梦cms后台系统基本参数里是无法直接上传图片的,我们更换logo图只能到ftp里替换,非常的不方便,我们如果想直接在系统基本参数里上传,要怎么处理呢?在这里需要对代码进行修改,具体流程如下: 实现方法,打开/dede/templets/sy