dedecms織夢怎麼自訂表單匯出到excel?
修改2個文件,讓織夢自定義表單自由匯出到Excel表格裡。
推薦學習:織夢cms
修改教學如下:
1、\dede\templets\diy_main.htm 找到
#前台預覽5db79b134e9f6b82c0b36e0489ee08ed
<a href="diy_list.php?action=excel&diyid={dede:field.diyid/}" target="_blank">导出表单Excel</a>
2、\dede\diy_list.php 找到
array('post', 'list', 'edit', 'check', 'delete'))
改成
array('post', 'list', 'edit', 'check', 'delete', 'excel'))
繼續找到
else { showmsg('未定义操作', "-1"); }
在它的上面加入
else if($action == 'excel') { header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:attachment;filename={$diy->name}_".date("Y-m-d").".xls"); $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>"; }
以上是dedecms織夢怎麼自訂表單匯出到excel的詳細內容。更多資訊請關注PHP中文網其他相關文章!