后台:
# 菲律賓名單word導出
public function export_word(){
$tids = $_GET['tids'];
$userinfo=M("philippines_visa")->where(["philippines_id"=>$tids])->select();
foreach ($userinfo as $key => $value) {
$userinfo[$key]['birth'] = explode('-', $value['date_of_birth']); # 出生日期
$userinfo[$key]['birth_m'] = $this->get_month($userinfo[$key]['birth']['1']);#月份英文
$userinfo[$key]['lssue'] = explode('-', $value['lssue_date']); # 簽發日期
$userinfo[$key]['lssue_m'] = $this->get_month($userinfo[$key]['lssue']['1']);#月份英文
$userinfo[$key]['expiration'] = explode('-', $value['expiration_date']); # 有效日期
$userinfo[$key]['expiration_m'] = $this->get_month($userinfo[$key]['expiration']['1']);#月份英文
}
$user_info = $userinfo;
$user_info = array_chunk($user_info, 20, true); # 拆分為20個元素一組的多維數組 (需求而已)
$this->assign('user_info',$user_info);
$filename = '名單';
ob_start(); //打開緩沖區
$this->display();
header("Cache-Control: public");
Header("Content-type: application/octet-stream");
Header("Accept-Ranges: bytes");
if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) {
header('Content-Disposition: attachment; filename='.$filename.'.doc');
}else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) {
Header('Content-Disposition: attachment; filename='.$filename.'.doc');
} else {
header('Content-Disposition: attachment; filename='.$filename.'.doc');
}
header("Pragma:no-cache");
header("Expires:0");
ob_end_flush();//輸出全部內容到瀏覽器
}
前端頁面:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>菲律賓簽證</title>
<style>
@page{
margin: 30px;
}
.box{page-break-after:always;}
input{font-family: '宋體';}
table{
border-collapse: collapse; /*設置列、行間距*/
}
table td,table th{
text-align:center;
}
</style>
</head>
<body>
<!-- 名單模板三 -->
<foreach name="user_info" item="user_page" key="key">
<div class="box box7 page" style="border-bottom:none;">
<table>
<tr>
<th style="width:4%;border:1px solid #000"></th>
<th style="width:10%;border:1px solid #000">SURNAME</th>
<th style="width:12%;border:1px solid #000">GIVEN NAME</th>
<th style="width:5%;border:1px solid #000">SEX</th>
<th style="width:5%;border:1px solid #000">(Birth Month) MM</th>
<th style="width:5%;border:1px solid #000">(Birth Day) DD</th>
<th style="width:5%;border:1px solid #000">(Birth Year) YY</th>
<th style="width:12%;border:1px solid #000">Passport Number</th>
</tr>
<tbody class="">
<foreach name="user_page" item="vo" key="k">
<tr>
<td style="border:1px solid #000">{$k+1}</td>
<td style="border:1px solid #000">{$vo.english_name}</td>
<td style="border:1px solid #000">{$vo.english_name_s}</td>
<td style="border:1px solid #000"><eq name='vo.m_sex' value='男'>M<else />F</eq></td>
<td style="border:1px solid #000">{$vo['birth']['1']}</td>
<td style="border:1px solid #000">{$vo['birth']['2']}</td>
<td style="border:1px solid #000">{$vo['birth']['0']}</td>
<td style="border:1px solid #000">{$vo.m_visa_number}</td>
</tr>
</foreach>
</tbody>
</table>
</div>
</foreach>
</body>
</html>
呈現:

