php phpword生成html页面
2024-08-27 02:58:21
先说下需求:正常点击免责声明是下载的文件,根据用户需求是点击预览,所以这里利用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 PhpOffice\PhpWord\IOFactory;
use PhpOffice\PhpWord\PhpWord; public function ajax(){
//根据id查询数据库存的文档路径
$file_id = $_POST['id'];
$info = M('download_file')->where(['file_id'=>$file_id])->find();
$IOFactory = new PhpWord();
$phpWord = \PhpOffice\PhpWord\IOFactory::load('./'.$info['file_url']);
$xmlWriter = \PhpOffice\PhpWord\IOFactory::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);
}
}
最新文章
- css常用hack
- 生成模型(Generative Model)与判别模型(Discriminative Model)
- 基于pygtk的linux有道词典
- rabbitmq使用
- Android 使用库项目时的一个特殊tip
- POJ 1743 Musical Theme 后缀数组 最长重复不相交子串
- hdoj 5494 Card Game
- 在mac本上折腾android 开发环境
- C++ fstream 详解
- 单链表反转java代码
- Kafka:ZK+Kafka+Spark Streaming集群环境搭建(三十):使用flatMapGroupsWithState替换agg
- vscode 常用扩展推荐
- maven windows环境nexus3.0私服搭建
- Postgresql 日志审计
- The String class&#39;s judging function
- 【codechef】Children Trips
- strptime和strptime函数理解
- php获取不到url问号之后的参数
- win7查看某个端口被占用的解决方法
- python_29_三级菜单
热门文章
- Flink(一)集群配置
- Mac系统下安装Homebrew后无法使用brew命令
- dependency与dependencyManagement区别
- OC学习篇之---对象的拷贝
- jdbc 可处理数据库事物的通用增删查改函数
- Service系统服务(三):查看进程信息、进程调度及终止、系统日志分析、使用systemctl工具
- vue常见面试题
- Oracle数据库中,sql中(+)(-)的含义
- js调用ios和安卓方法
- MySQL concat、concat_ws 和 group_concat 的用法