Pursuing a dream dedecms custom form export to excel tutorial

Death does not write any of the fields, do not write anything dead, modify two files so that custom forms weaving dreams free export to Excel spreadsheet.

Adding Tutorial

 

1, \ dede \ templets \ diy_main.htm found

Reception preview </a>

 

Add a line below it

| <a href="diy_list.php?action=excel&diyid={dede:field.diyid/}" target="_blank">导出表单Excel</a>

 

2, \ dede \ diy_list.php found

array('post', 'list', 'edit', 'check', 'delete'))

Change

array('post', 'list', 'edit', 'check', 'delete', 'excel'))

 

Continue to find

else

{

    ShowMsg ( "Undefined", "-1");

}

 

Added on top of it

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> state </ 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 'audited': 'unaudited';

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

                   echo "</tr>";

         }

         echo "</table>";

}

 

carry out.

 

Guess you like

Origin www.cnblogs.com/liu-zhijun/p/11529093.html