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>