zoukankan      html  css  js  c++  java
  • php phpword生成html页面

    先说下需求:正常点击免责声明是下载的文件,根据用户需求是点击预览,所以这里利用phpword生成一个静态页面并进行预览。不多说,直接上代码附带类文件。

    类文件:https://pan.baidu.com/s/1yhZu5JyrtIfKnGllRblPtg  提取码:fbu3  把类文件放在vendor目录下。

    html代码:

    <!-- 这里是点击下载的html代码,隐藏域是当前的id -->
    <p><input type="hidden" value="{$vo.file_id}" class="file_id"><a href="#" class="btn btn-primary click">点击下载</a></p>
    
    <script type="">
        //触发ajax把id传到控制器
        $('.click').click(function(){
            id = $(this).prev().val();
             $.ajax({
                type: "POST",
                url: "{:url('home/Single/ajax')}",
                data: {id:id},
                dataType: "json",
                success: function (msg) {
                  window.open(msg.html)//新页面打开预览
                }
              });
             return false;
        })
    </script>
    

      后台代码:

    //首先头部引用类
    use PhpOfficePhpWordIOFactory;
    use PhpOfficePhpWordPhpWord;
    
    public function ajax(){
            //根据id查询数据库存的文档路径
            $file_id = $_POST['id'];
            $info = M('download_file')->where(['file_id'=>$file_id])->find();
            $IOFactory = new PhpWord();
            $phpWord = PhpOfficePhpWordIOFactory::load('./'.$info['file_url']);
            $xmlWriter = PhpOfficePhpWordIOFactory::createWriter($phpWord, "HTML");
            //生成hello.html文件路径
            $xmlWriter->save('./Public/doc/hello.html');
            //判断文件是否存在,额庵后传到前台
            if(file_exists('./Public/doc/hello.html')){
                $html='/Public/doc/hello.html';
                $dataa = array('html'=>$html,'url'=>$url);
                echo json_encode($dataa);
                
            }else{
                $dataa = array('html'=>'0');
                echo json_encode($dataa);
            }
        }
    

      

  • 相关阅读:
    BZOJ 2006 [NOI2010]超级钢琴
    标准打印一棵树
    COJ 0288 路径(2015升级版)
    批判树套树。。。。。。。。
    BestCoder Round #49
    蓝牙通信中读取固定长度数组的解决
    5月5日的规划
    必须要改变这样的生活
    五一结束
    五一来临
  • 原文地址:https://www.cnblogs.com/dalaowang/p/11866758.html
Copyright © 2011-2022 走看看