1、本文原創
2、利用原生php,將HTML導出word並下載
3、效果:
4、代碼:
php部分
fucntion exportWord(){
$this->assign('profession_name',$profession_name);
$this->assign('_list',$_arr);
//return $this->fetch('Graduation/do_mingce');
//---------- PHP原生導出word:測試通過 -----------
echo $this->fetch('Graduation/do_mingce_by_php');
$filename = '武漢****學院畢業離校告知書';
ob_start(); //打開緩沖區
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();//輸出全部內容到瀏覽器
//---------- PHP原生導出word end ! -----------
}
HTML部分:
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <xml><w:WordDocument><w:View>Print</w:View></xml> <style id="list"> .title{text-align:center;} .gaozhi{text-align:center;fong-weight:100} </style> </head> <body> <div class="content" id="form1"> <div class="title"> <span>武漢****學院畢業離校告知書</span> </div> <div class="header"> <span class="gaozhi"><b>{:htmlspecialchars_decode($content)}</b></span> </div> </div> </body> </html>