• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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>

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
CentOS安装php7.0发布时间:2022-07-10
下一篇:
PHP:引用Phpword导出数据到word文档发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap