其实网上有很多的教程了,包括官网也有,
不过出于一些原因,导入导出可能会失败,这里结合网上各教程总结一下
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();
}
}