元素模板为您解答:
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']=='soid'){echo "<th>品牌</th>";}elseif($row['Field']=='prid'){echo "<th>车系</th>";}elseif($row['Field']=='realname'){echo "<th>姓名</th>";}elseif($row['Field']=='mp'){echo "<th>电话</th>";}elseif($row['Field']=='mytime'){echo "<th>报名时间</th>";}elseif($row['Field']=='tel'){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>";}