日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

关于纯HTML格式写入word

發布時間:2025/3/15 HTML 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 关于纯HTML格式写入word 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

  用mht格式生成的word文檔不適合批量導出,用純HTML生成的word文件可以批量導出。我不適用框架直接用localhost本地執行PHP文件的格式如下:

<?php header("content-type:text/html;charset=utf-8"); 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">';}function save($path){ echo "</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);} } $basic_code = '001'; $sce_name = '大明湖'; $sce_status = '已開發'; $area_name = '山東省濟南市歷下區'; $sce_addr = '山東省濟南市歷下區'; $sce_coord = '117.03246,36.680728'; $sce_form = '兩面荷花三面柳,半城山色半城湖'; $now_status = '收費+免費'; $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"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <xml><w:WordDocument><w:View>Print</w:View></xml> </head>'; $html .= '<body> <h1 style="text-align:center">旅游資源普查表</h1> <div> <span>代碼:'.$basic_code.'</span> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span>序號:</span> </div> <table border="1" cellpadding="3" cellspacing="0"> <tr><td width="100">名&nbsp;&nbsp;稱:</td><td width="700" colspan="12">'.$sce_name.'</td> </tr> <tr><td width="100">開發狀況:</td><td width="700" colspan="12">'.$sce_status.'</td> </tr> <tr><td width="100">所屬管轄:</td><td width="700" colspan="12">'.$area_name.'</td> </tr> <tr><td width="100">位&nbsp;&nbsp;置:</td><td width="700" colspan="12">'.$sce_addr.'</td> </tr> <tr><td width="100">地理坐標:</td><td width="700" colspan="12">'.$sce_coord.'</td> </tr> <tr><td width="100">基本特征:</td><td width="700" colspan="12">&nbsp;&nbsp;'.$sce_form.'</td> </tr> <tr><td width="100">保護與開發現狀:</td><td width="700" colspan="12">'.$now_status.'</td> </tr>'; // foreach($img_src as $v){// $html .= '<tr>// <td width="100" valign="center" >圖片顯示</td>// <td width="700" valign="center" colspan="12" ><img src="'.$v.'" width="400" /></td>// </tr>'; // } $html .= '</table></body>'; //批量生成(自己修改) for($i=1;$i<=3;$i++){ $word = new word(); $word->start(); //$html = "aaa".$i; $wordname = 'test'.$i.".doc"; echo $html; $word->save($wordname); ob_flush();//每次執行前刷新緩存 flush(); }

  注意:該php文件只在本地(服務器)生成word文檔,沒有寫下載功能。如有需要請參考《生成mht格式導出word》那篇文檔。

總結

以上是生活随笔為你收集整理的关于纯HTML格式写入word的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。