<a href="../plus/diy.php?action=list&diyid={dede:field.diyid/}" target="_blank"><img src='images/gtk-tmp.png' title='预览' alt='预览' />前台预览</a>
在后面加上:
| <a href='diy_list.php?action=excel&diyid={dede:field.diyid/}' target="_blank">导出表单Excel</a>
2 修改 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 : '';
在最底部 大约223行出
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>";
}
后台-更新下缓存 版权声明: 本站资源均来自互联网或会员发布,如果侵犯了您的权益请与我们联系,我们将在24小时内删除!谢谢!
转载请注明: 织梦cms自定义表单导出EXCEL的方法