【原生PHP】php导出word(无需引入phpword插件)


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>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM