PHP生成word文档
2018-01-06 15:47
786 查看
ob_start(); //打开缓冲区 echo ' <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" > <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <xml><w:WordDocument><w:View>Print</w:View></xml> </head>'; echo '<body> <h1 style="text-align: center">这是一个word文档</h1> <img src="D:\phpStudy\WWW\111.png" alt="" /> </body>'; header("Cache-Control: no-store"); //所有缓存机制在整个请求/响应链中必须服从的指令 Header("Content-type: application/octet-stream"); //用于定义网络文件的类型和网页的编码,决定文件接收方将以什么形式、什么编码读取这个文件 Header("Accept-Ranges: bytes"); //Range防止断网重新请求 。 if (strpos($_SERVER["HTTP_USER_AGENT"],'MSIE')) { header('Content-Disposition: attachment; filename=test.doc'); }else if (strpos($_SERVER["HTTP_USER_AGENT"],'Firefox')) { Header('Content-Disposition: attachment; filename=test.doc'); } else { header('Content-Disposition: attachment; filename=test.doc'); } header("Pragma:no-cache"); //不能被浏览器缓存 header("Expires:0"); //页面从浏览器高速缓存到期的时间分钟数,设定expires属性为0,将使对一页面的新的请求从服务器产生 ob_end_flush();//输出全部内容到浏览器注意:
1.所有样式必须写在行内,不然word不识别。
2.引入图片必须要写绝对路径。
相关文章推荐
- PHP由HTML生成Word文档及编码转换
- PHP生成word文档
- PHPWord利用模板替换字符串生成精确的word文档
- php用PHPWord库生成word文档的例子
- PHPWord生成多篇word文档的时候目录文件冗余bug解决方案
- PHP实现生成word文档
- php 生成 word 文档
- PHP生成word文档的三种实现方式
- 利用PHPWord生成文档的应用例子
- PHPWord利用模板替换字符串生成精确的word文档
- phpword生成word文档
- php在程序中把网页生成word文档并提供下载
- 在Windows系统下使用PHP生成Word文档的教程
- PHP生成word文档,表格实例
- Laravel生成Word文档 - phpword
- php生成word文档
- Laravel生成Word文档 - phpword
- 【原】php生成2003 word文档并以页面视图打开
- 【原】php自动生成带图片附件的word文档类
- php在程序中将网页生成word文档并提供下载的代码