zoukankan      html  css  js  c++  java
  • php 导出word文档

    //前台
       
        <button onclick="export_word()" >导出word</button>
       
        <script>
            function export_word(){
                location.href = "{:url('Home/index/down_word')}"
            }
        </script>
    //后台
        public function down_word(){
            $row = Db::name('article')->find(1);
            $this->export_word($row['title'], $row['content']);
        }
        
        
        private  function export_word($title,$content){
            $content = str_replace("src="/", "src="http://www.XXX.com/", $content); //给是相对路径的图片加上域名变成绝对路径,导出来的word就会显示图片了  
            $filename = iconv('utf-8', 'gb2312', $title);
            header('pragma:public');
            header('Content-type:application/vnd.ms-word;charset=utf-8;name="' . $filename . '".doc');
            header("Content-Disposition:attachment;filename=$filename.doc"); //attachment新窗口打印inline本窗口打印  
            $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"><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'; //这句不能少,否则不能识别图片  
            echo $html . $content . '</html>';
        }
  • 相关阅读:
    DateTime.now()用法
    C#中静态类详述
    面向对象详述
    解决Github打不开问题
    git 提交代码流程 先暂存 在提交+备注 然后拉取代码获取最新的代码 然后再推送 git push
    常用
    样式重置
    Html 5优化
    理解js闭包
    css 倒计时 svg
  • 原文地址:https://www.cnblogs.com/kerryw/p/8271132.html
Copyright © 2011-2022 走看看