注意的问题:
1、身份证号码18位导出到excel时是科学计数法,可以在excel表格中转换文本格式来恢复正常。
操作方法
https://jingyan.baidu.com/article/8ebacdf0d76c6349f65cd5ff.html
2、使用织梦自带的地区联动时,导出的是枚举数无法转换,所以需要导出excel时还是建议使用js插件做联动。
导出excel方法
1、dede/templets/diy_main.htm 找到
前台预览</a>
在它的下面加入一行
<a href="diy_list.php?action=excel&diyid={dede:field.diyid/}" target="_blank">导出表单Excel</a>
2、dede/diy_list.php 找到最下面的
else
{
showmsg('未定义操作', "-1");
}
在这一段else前面加上
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>";
}
3、还是dede/diy_list.php
找到大约第14行
$action = isset($action) && in_array($action, array('post', 'list', 'edit', 'check', 'delete')) ? $action : '';
在delect后面添加 ,'excel' 效果如下
$action = isset($action) && in_array($action, array('post', 'list', 'edit', 'check', 'delete', 'excel')) ? $action : '';
这样就完成导出功能了。