简要前端:
<div>
<div id="title">社团活动报名系统</div>
<div>
<form action="{:url('index/baoming')}" METHOD="post" ACCEPT-CHARSET="utf-8">
<table width="20%" border="0" cellpadding="0" cellspacing="2" align='center' valign='middle'>
<tr>
<td>姓名:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>手机号:</td>
<td><input type="text" name="tel"></td>
</tr>
<tr>
<td>邮箱:</td>
<td><input type="text" name="email"></td>
</tr>
<tr>
<td>专业:</td>
<td><input type="text" name="subject"></td>
</tr>
<tr>
<td>学号:</td>
<td><input type="text" name="studentid"></td>
</tr>
<tr>
<td height="26" colspan="2" align="center" valign="middle"><input type="submit" name="tijiao" value="报名" style="width:60px; height:30px" ></td>
</tr>
</table>
</form>
<div id="excel">
<a style="text-decoration:none" href="{:url('excel')}" class="btn btn-info radius" id="daochu"><i class="fa fa-search"></i>导出数据</a>
</div>
</div>
</div>
public function baoming()
{
$request=request();
$username = $request->param('username');
$tel = $request->param('tel');
$email = $request->param('email');
$subject = $request->param('subject');
$studentid = $request->param('studentid');
$data =[
'username'=>$username,
'tel'=>$tel,
'email'=>$email,
'subject'=>$subject,
'studentid'=>$studentid
];
$a = Db::table('user')->insert($data);
$b = Db::table('user')->getLastInsID();
if($a){
$this->success('报名成功,您的识别码为:0000'.$b);
}
else{
echo '输入信息有误';
}
}
public function excel()
{
//导出
//##########################################################################
$list = Db::name("user")->select();
$file_name = date('Y-m-d_His').'.xls';
$path = dirname(__FILE__);
Loader::import('PHPExcel.Classes.PHPExcel');
Loader::import('PHPExcel.Classes.PHPExcel.IOFactory.PHPExcel_IOFactory');
$PHPExcel = new \PHPExcel();
// print_r($PHPExcel);die;
$PHPSheet = $PHPExcel->getActiveSheet();
$PHPSheet->setTitle("报名信息");
$PHPSheet->setCellValue("A1","ID");
$PHPSheet->setCellValue("B1","姓名");
$PHPSheet->setCellValue("C1","手机号");
$PHPSheet->setCellValue("D1","邮箱");
$PHPSheet->setCellValue("E1","专业");
$PHPSheet->setCellValue("F1","学号");
$i = 2;
foreach($list as $key => $value){
$PHPSheet->setCellValue('A'.$i,''.$value['Id']);
$PHPSheet->setCellValue('B'.$i,''.$value['username']);
$PHPSheet->setCellValue('C'.$i,''.$value['tel']);
$PHPSheet->setCellValue('D'.$i,''.$value['email']);
$PHPSheet->setCellValue('E'.$i,''.$value['subject']);
$PHPSheet->setCellValue('F'.$i,''.$value['studentid']);
$i++;
}
$PHPWriter = \PHPExcel_IOFactory::createWriter($PHPExcel,"Excel2007");
header('Content-Disposition: attachment;filename='.$file_name);
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$PHPWriter->save("php://output");
}
焚膏油以继晷,恒兀兀以穷年。