首页» [源码] » dede自定义表单导出EXCEL表格

dede自定义表单导出EXCEL表格

Author:网络营销师王健 2019-9-21 12:16 Saturday 105 0 发表评论

方法一:

 

后台找到/dede/templets/diy_main.htm

查找:

 

<a href="../plus/diy.php?action=list&diyid={dede:field.diyid/}" target="_blank"><img src='images/gtk-tmp.png' title='预览' alt='预览' />前台预览</a>


在后面加上:

 

&nbsp;|&nbsp;<a href='diy_list.php?action=excel&diyid={dede:field.diyid/}' target="_blank">导出表单Excel</a>


修改/dede/diy_list.php,在其中搜索:

 

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

修改为:


 

$action = isset($action) && in_array($action, array('post', 'list', 'edit', 'check', 'delete','excel')) ? $action : '';


再找到:


 

else{ showmsg('未定义操作', "-1"); }


在它前面添加:


elseif($action == 'excel')
{   
    ob_end_clean();//清除缓冲区,避免乱码
    header("Content-type:application/vnd.ms-excel");
    header("Content-Disposition:attachment;filename={$diy->name}_".date("Y-m-d").".xls");
    print(chr(0xEF).chr(0xBB).chr(0xBF));//清除bom
    $fieldlist = $diy->getFieldList();
    echo "<table><tr>";
    foreach($fieldlist as $field=>$fielddata)
    {
        echo "<th>{$fielddata[0]}</th>";
    }
    echo "<th>状态</th>";
    echo "</tr>";
    $sql = "SELECT * FROM {$diy->table} ORDER BY id DESC";
    $dsql->SetQuery($sql);
    $dsql->Execute('t');
    while($arr = $dsql->GetArray('t'))
    {
        echo "<tr>";
        foreach($fieldlist as $key => $field)
        {
            echo "<td>".$arr[$key]."</td>";
        }
    $status = $arr['ifcheck'] == 1 ? '已审核' : '未审核';
    echo "<td>".$status."</td>";
    echo "</tr>";
    }
    echo "</table>";
}

 

 

 

方法二,较麻烦,未亲测:

1.首先在后台找到/dede/templets/diy_main.htm,查找:


<a href="../plus/diy.php?action=list&diyid={dede:field.diyid/}" target="_blank"><img src='images/gtk-tmp.png' title='预览' alt='预览' />前台预览</a>
在后面加上:
&nbsp;|&nbsp;<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';

 

3、再在plus/diy.php最后一行下面新加代码:

 

else if($action == 'daochu')
{
ob_end_clean();//清除缓冲区,避免乱码
header("Content-type:application/vnd.ms-excel;");
Header("Content-Disposition:attachment;filename={$diy->table}_".date("Y-m-d").".xls");
print(chr(0xEF).chr(0xBB).chr(0xBF));//清除bom
$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']=='gsm'){
            echo "<th>公司名</th>";
        }elseif($row['Field']=='xm'){
            echo "<th>姓名</th>";
        }elseif($row['Field']=='sj'){
            echo "<th>手机号码</th>";
        }elseif($row['Field']=='yx'){
            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>";
}

 

 

原文地址:https://blog.csdn.net/jklgfgdsr/article/details/79311950

 



引用地址:

联系我Contact Me

bloggerBlogger

一个网络营销师,一个SEOer,一个服务器管理人员,一个网页制作人员.
网络人才博客,关注互联网,网络营销相关知识,网络营销师王健hack001.com.

最新碎语New Twitters更多...

  • 任何骚扰性质的营销都是失...

    10-20 02:13

  • RTBAsia+商盾+转化分析= 哪...

    08-30 10:35

  • 不管是手机,微信,人与事...

    06-22 03:44

  • 变数最大的3样东西:计划...

    06-17 12:06

  • 有志者事竟成,细到极致者...

    06-15 13:23

  • 更多»

日历Calendar

搜索Search

标签云