Custom form export excel

Keywords: Excel PHP SQL

Attention:

1. When the ID card number 18 bits is exported to excel, it is a scientific counting method, which can convert text format in Excel table to restore normal.

Operating method

https://jingyan.baidu.com/article/8ebacdf0d76c6349f65cd5ff.html

2. When using the regional linkage brought by Zhimeng, the derived enumerator cannot be converted, so it is recommended to use the js plug-in when exporting excel.

 

Derived excel method

1. dede/templets/diy_main.htm found

Front desk preview</a>

Add a line below it

<a href="diy_list.php?action=excel&diyid={dede:field.diyid/}" target="_blank">Export form Excel</a>

2. dede/diy_list.php finds the bottom

else
{
    showmsg('Undefined operation', "-1");
}

Before this paragraph else, add

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' : 'Not audited';
echo "<td>".$status."</td>";
echo "</tr>";
}
echo "</table>";
}

3. dede/diy_list.php

Find about line 14

$action = isset($action) && in_array($action, array('post', 'list', 'edit', 'check', 'delete')) ? $action : '';

Add after delect,'excel'works as follows

$action = isset($action) && in_array($action, array('post', 'list', 'edit', 'check', 'delete', 'excel')) ? $action : '';

This completes the export function.

Posted by schwa97 on Tue, 08 Oct 2019 18:49:57 -0700