PHP将HTML的内容保存成word文档

<?php 

class word
{
    function start()
    {
        ob_start();
        echo ‘<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>
            </head><body>‘;
    }
    function save($path)
    {

        echo "</body></html>";
        $data = ob_get_contents();
        ob_end_clean();

        $this->wirtefile ($path,$data);
    }

    function wirtefile ($fn,$data)
    {
        $fp=fopen($fn,"wb");
        fwrite($fp,$data);
        fclose($fp);
    }
}

/*生成doc文件*/
$html = ‘<style>
.onle_bm{ width:50%; line-height:50px; font-size:24px; text-align:center; color:#000;margin: 0px auto;}
.onle_bts{ width:50%; line-height:30px; font-size:16px; color:#666; margin:0px auto;}
.onle_bd{ width:50%; margin:0px auto; padding-top:20px;}
.onle_bd table{ border-right: 1px solid #000;  border-bottom: 1px solid #000;height: 40px;}
.onle_bd td{font-size: 14px; color: #000; border-left: 1px solid #000;  border-top: 1px solid #000;height: 40px;}

</style><div class="onle_bm">国家登记表</div>
<div class="onle_bts">报名序号:<span>20170001</span></div>
<div class="onle_bd">
<form action="" method="get">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr>
   <td width="14%" align="center"><p >报考岗位</p></td>
   <td width="34%"><label for="textfield"><p>‘.$_POST[‘bkgw‘].‘</p></label>
     </td>
   <td width="11%" align="center"><p >专业类别</p></td>
   <td colspan="2">‘.$_POST[‘sxzy‘].‘</td>
   <td width="18%" rowspan="4"><img src="https://img6.bdstatic.com/img/image/smallpic/t2.jpg" width="100px" height="100px" /></td>
 </tr>
 <tr>
   <td align="center"><p >姓名 </p></td>
   <td><p>‘.$_POST[‘username‘].‘</p></td>
   <td align="center"><p >出生年月</p></td>
   <td colspan="2" align="center"><p >‘.$_POST[‘csmy‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >户口所在地</p></td>
   <td><p >‘.$_POST[‘hjaddress‘].‘</p></td>
   <td align="center"><p >性别</p></td>
   <td colspan="2" align="center"><p >‘.$_POST[‘sex‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >政治面貌</p></td>
   <td align="center"><p >‘.$_POST[‘zzmm‘].‘</p></td>
   <td align="center"><p >婚姻状况</p></td>
   <td colspan="2" align="center"><p >‘.$_POST[‘hyzk‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >最高学历 </p></td>
   <td align="center"><p >‘.$_POST[‘zgxl‘].‘</p></td>
   <td align="center"><p >毕业证号</p></td>
   <td width="11%" align="center"><p>‘.$_POST[‘byzh‘].‘</p></td>
   <td width="12%" align="center"><p >学位</p></td>
   <td align="center"><p >‘.$_POST[‘degree‘].‘</p></td>
 </tr>
 <tr>
   <td align="center"><p >毕业院校 </p></td>
   <td colspan="3"><p>‘.$_POST[‘byyx‘].‘</p></td>
   <td align="center"><p >所学专业</p></td>
   <td align="center"><p >‘.$_POST[‘sxzy‘].‘</p></td>
 </tr>
 <tr>
   <td align="center"><p >现工作单位</p></td>
   <td colspan="3"><p>‘.$_POST[‘xgzdw‘].‘</p></td>
   <td align="center"><p >曾担任职务 </p></td>
   <td align="center"><p >‘.$_POST[‘cdrzw‘].‘</p></td>
 </tr>
 <tr>
   <td align="center"><p >通讯地址</p></td>
   <td colspan="3"><p>‘.$_POST[‘txaddress‘].‘</p></td>
   <td align="center"><p >邮政编码</p></td>
   <td align="center"><p >‘.$_POST[‘yzbm‘].‘</p></td>
 </tr>
 <tr>
   <td align="center"><p >现居住地</p></td>
   <td colspan="3">‘.$_POST[‘xjzaddress‘].‘</td>
   <td align="center"><p >移动电话</p></td>
   <td align="center"><p>‘.$_POST[‘ydphone‘].‘</p></td>
 </tr>
 <tr>
   <td align="center"><p >身份证号</p></td>
   <td><p>‘.$_POST[‘idcard‘].‘</p></td>
   <td align="center"><p >电子邮箱</p></td>
   <td colspan="3"><p>‘.$_POST[‘email‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >掌握何种外语及程度</p></td>
   <td align="center"><p >‘.$_POST[‘zwwycd‘].‘</p></td>
   <td align="center"><p >计算机掌握程度</p></td>
   <td align="center"><p >‘.$_POST[‘jsjzwcd‘].‘</p></td>
   <td align="center"><p >有无刑事记录</p></td>
   <td align="center"><p >‘.$_POST[‘xsfzjl‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >毕业年份</p></td>
   <td align="center"><p >‘.$_POST[‘bynf‘].‘</p></td>
   <td colspan="3" align="center"><p >直系亲属是否从事商标代理</p></td>
   <td align="center"><p >‘.$_POST[‘zxqscssbdl‘].‘</p></td>
 </tr>
 <tr>
   <td align="center"><p >学习经历 </p></td>
   <td colspan="5"><label for="textarea"></label><p>
    ‘.$_POST[‘xxjsxjl‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >工作经历 </p></td>
   <td colspan="5"><p>‘.$_POST[‘gzjl‘].‘</p></td>
   </tr>
 <tr>
   <td align="center"><p >奖惩情况</p></td>
   <td colspan="5"><p>‘.$_POST[‘jcqk‘].‘</p></td>
   </tr>
 <tr>
   <td rowspan="2" align="center"><p align="center" >家庭成员和 <br />
     主要社会 <br />
     关系 </p></td>
   <td align="center"><p >姓名 </p></td>
   <td align="center"><p >关系 </p></td>
   <td colspan="2" align="center"><p >所在单位职务 </p></td>
   <td align="center"><p >政治面貌 </p></td>
 </tr>
 <tr>
   <td colspan="5"></td>
   </tr>
 <tr>
   <td align="center"><p >备注</p></td>
   <td colspan="5">‘.$_POST[‘bz‘].‘</td>
   </tr>
</table>

</form>
</div>
<div class="onle_bts">注:最高学历为国家承认的学历</div>
‘;

$html = file_get_contents("http://www.xxxx.com/test.html");
// echo $html;exit;

$word = new word();
$word->start();
$wordname = ‘word/test.doc‘;//生成文件路径
echo $html;
$word->save($wordname);
ob_flush();//每次执行前刷新缓存
flush();
/*生成doc文件 end*/

  

时间: 2024-08-26 07:17:44

PHP将HTML的内容保存成word文档的相关文章

“Word自动更改后的内容保存到通用文档模板上。是否加载该模板?“的解决办法

在win7系统下,Word2010出现了不能正常关闭.打开一个已有word文档,点击右上角关闭按钮后,先提示"word已停止工作,windows正在检查该问题的解决方案",随后提示"Microsoft word正试图恢复您的信息,这可能需要几分钟",最后提示"Microsoft Word已停止工作,出现了一个问题,导致程序停止正常工作.如果有可用的解决方案,Windows将关闭程序并通知您".之后,再重新打开word时,提示"Word自

怎样可以把excel表格转换成word文档

在处理一些文档时,有时会遇到需要将excel表格内容全部放到word文档中,通常只是需要excel的部分数据内容时,直接通过复制,然后粘贴到word文档中即可,但是如果需要将excel表格所以内容都转换成word,那么复制操作就比较麻烦了,那么怎样可以快速将excel表格转换成word文档呢? 通过文档的转换工具,可以将excel格式直接转为word文档,而且是将excel工作簿中的所有表格同时进行转换. 首先在转换器中选择文件转word的转换类型,通过这个选项可以把我们常见的excel,ppt

怎么把PDF转换成word文档编辑

很多办公类的文档都是用word编辑的,而现在很多场合都需要用到PDF文件,所以在发送文件时都会以PDF文件格式方式发送,如果接收到这种格式文件需要对文档内容进行编辑调整又或是需要运用到里面的一些内容信息,直接编辑还是有些麻烦的,但是可以把PDF文件转换成word文档,然后再对word文件编辑利用就简单多了. 想要将PDF转成word得使文件内容没有大的变动,最好和原PDF文件保存一致,直接复制粘贴的方法是不行的,需要直接转换文档的格式.如果文档有编辑限制或者是加密的,则需要先去除这些限制. 转换

Wps文件如何转成word文档

Wps与word是大家日常学习办公当中使用得两种文字编辑工具.虽然说两者的功能大径相同,操作难易度也差不多.但是每个人都有自己的操作习惯,有人就习惯使用word工具.因此学习工作当中的文件格式也都是word格式.如果你突然让他用wps去编辑修改一份wps文档,或许他也能够完成.但是完成操作的时间会增长,编辑修改出来的文档内容质量也会有所下降.所以为了不影响学习工作结果,可将手中的wps文件转换为word文档,再进行文件内容的修改,这样会编辑轻松很多.今天文章内容中,就将和大家好好说说wps文件如

转换专家教你怎样把pdf转换成word文档

将pdf转换成word文档是让我们非常头疼的转换问题,由于在工作中出现的频率越来越多,不得不被重视起来,随之而来的是一系列的文本格式转换工具,主要是pdf格式转换工具.虽然很多工具都能够将pdf转换成word,但效果就不能保证了,小编在工作上还是比较敬业的,当即寻找文件格式转换专家来帮忙,想要把pdf转word的效果变成更好,转换的更加舒心,就让转换专家教怎样把pdf转换成word文档吧. 转换专家表示:在工作中接触pdf文件的朋友都知道,我们常常需要导出pdf中的图片.将pdf转换成offic

php将html转成word文档下载

<meta charset="utf-8" /> <?php class word{ function start(){ ob_start(); echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/

PDF如何转换成word文档

PDF如何转换成word文档 工作闲暇之际想将报刊.纸质文件这些文本资料上的文字变成自己的“东西”,但苦于文字资料太长,工作时间又紧,加上自己的打字速度太慢而不像花钱找专业打字员,有没有更好的方法来解决?答案是肯定的,那就是在网上下载一个迅捷PDF转换器软件,只需几分钟就能搞定,为你的编辑文档省钱又省力. 这里运用迅捷PDF转换器正式版本(当前最新版PDF文件转换软件)为例,利用软件内置的识别技术来解析PDF转Word.Excel.TXT等文本,希望对感兴趣的朋友有所帮助. 第一步,选择形式,勾

ABBYY将JPEG文件转换成Word文档的方法

日常工作中处理JPEG格式的图像文件时,有时需要转换成Word文档进行编辑,市场上应用而生了很多转换工具,相信不少人听说过OCR(光学字符识别)软件,可以用来转换图像文件,而在OCR软件中, ABBYY FineReader 12已被越来越多的企业和个人熟知,在日常工作中的应用范围也越来月广泛,本文主要教大家使用ABBYY FineReader 12将JPEG文件转换成Word文档. ABBYY FineReader 12是一款OCR图文识别软件,可快速方便地将扫描纸质文档.PDF文件和数码相机

将pdf转换成word文档格式的方法

PDF文档的规范性使得浏览者在阅读上方便了很多,但是要提取里面的内容比较麻烦,其实只要找到有效的方法,想要编辑pdf也不是什么难事,下面就以大家常常碰到的pdf转word的问题为例,说说如何将pdf转换成word文档. 想要将pdf转换成word,第三方工具时少不了的,要么下载一个pdf转换器,要么使用可以在线转换的平台来转换. 在线转换可以转换2m大的文件,而且是免费的,文件大小合适的朋友用这个方法非常好,进入在线转换平台之后,先选择要转换的文件格式“pdf转word"; 然后单击选择文件按钮