当前位置:首 页>常见问题>织梦dedecms自定义表单导出到excel的方法>

织梦dedecms自定义表单导出到excel的方法

  1,在文件\dede\templets\diy_main.htm找到


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


  后面加


  <ahref='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:'';


  3,在


  else{


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


  }


  前面加入


  elseif($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($fieldlistas$field=>$fielddata)


  {


  echo"<th>{$fielddata[0]}</th>";


  }


  echo"<th>状态</th>";


  echo"</tr>";


  $sql="SELECT*FROM{$diy->table}ORDERBYidDESC";


  $dsql->SetQuery($sql);


  $dsql->Execute('t');


  while($arr=$dsql->GetArray('t'))


  {


  echo"<tr>";


  foreach($fieldlistas$key=>$field)


  {


  echo"<td>".$arr[$key]."</td>";


  }


  $status=$arr['ifcheck']==1?'已审核':'未审核';


  echo"<td>".$status."</td>";


  echo"</tr>";


  }


  echo"</table>";


  }