其實網上有很多的教程了,包括官網也有,
不過出於一些原因,導入導出可能會失敗,這裏結合網上各教程總結一下
public function export()
{
$data = listModel::all();
$cellName = [
['id', 'auto', 'ID'],
['name', 'auto', '級別名稱'],
['score', 'auto', '積分要求'],
['discount', 'auto', '享受折扣'],
['create_time', 'auto', '創建時間'],
['update_time', 'auto', '更新時間'],
['status', 'auto', '狀態']
];
foreach ($data as $key => $value) {
$data[$key] = [
'status' => ($value['status']==1) ? '啓用' : '禁用',
]
}
plugin_action('Excel/Excel/export', ['test', $cellName, $data]);
}
public function import()
{
if ($this->request->isPost()) {
if($_POST['files']) {
$excel_file = $this->request->post('file');
$full_path = getcwd() . get_file_path($excel_file);
$fields=array('name'=>'名稱','count'=>'申請量');
$result=plugin_action('Excel/Excel/import', [$full_path,$table='list',$fields,1,$where=array(),'id']);
$this->success($result['message']);
}
exit;
} else {
return ZBuilder::make('form')
->addFormItem('file', 'files', '附件')
->isAjax(false)
->fetch();
}
}