PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/jeecg-framework/src/main/java/org/jeecgframework/web/cgform/common/OfficeHtmlUtil.java

https://github.com/nic9805/jeecg
Java | 488 lines | 280 code | 67 blank | 141 comment | 2 complexity | df0e5f290ffd002ce829af370ec001f9 MD5 | raw file
Possible License(s): GPL-3.0, MPL-2.0-no-copyleft-exception, MIT
  1. package org.jeecgframework.web.cgform.common;
  2. import java.io.ByteArrayOutputStream;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.util.Map;
  10. import java.util.regex.Pattern;
  11. import javax.xml.parsers.DocumentBuilderFactory;
  12. import javax.xml.transform.OutputKeys;
  13. import javax.xml.transform.Transformer;
  14. import javax.xml.transform.TransformerFactory;
  15. import javax.xml.transform.dom.DOMSource;
  16. import javax.xml.transform.stream.StreamResult;
  17. import org.apache.poi.hwpf.HWPFDocument;
  18. import org.apache.poi.hwpf.converter.WordToHtmlConverter;
  19. import org.jeecgframework.core.util.LogUtil;
  20. import org.w3c.dom.Document;
  21. import org.jeecgframework.web.cgform.entity.config.CgFormFieldEntity;
  22. import com.jacob.activeX.ActiveXComponent;
  23. import com.jacob.com.Dispatch;
  24. import com.jacob.com.Variant;
  25. public class OfficeHtmlUtil {
  26. int WORD_HTML = 8;
  27. int WORD_TXT = 7;
  28. int EXCEL_HTML = 44;
  29. //清除HTML标签匹配内容
  30. private final static String regEx_style = "<[\\s]*?(style|xml|meta|font|xml|del|ins|o:p|head|!)[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?(style|xml|meta|font|xml|del|ins|o:p|head|>)[\\s]*?>";
  31. //清除多余属性匹配内容
  32. private final static String regEx_attr1 = "[\\s] ?xmlns?(:v|:o|:w|)=\"([^\"]+)\"";
  33. private final static String regEx_attr2 = "style=\'([^\']+)\'";
  34. private final static String regEx_attr3 = "[\\s]?(class|lang)=([^?(\\s|>)]+)";
  35. private final static String regEx_attr4 = "<span[^>]+>";
  36. private final static String regEx_attr5 = "<\\/span>";
  37. //过滤布局硬宽度
  38. private final static String regEx_attr7 = "width=.[0-9]*";
  39. //过滤文字顶格
  40. private final static String regEx_attr8 = "valign=top";
  41. //生成输入框匹配内容
  42. private final static String regEx_attr6 = "\\#{([a-zA-Z_0-9]+)\\}";
  43. //替换标签 针对于<input />类型标签
  44. private final static String regEx_replace = "[^>]+>";
  45. /**
  46. * WORD转HTML
  47. *
  48. * @param docfile
  49. * WORD文件全路径
  50. * @param htmlfile
  51. * 转换后HTML存放路径
  52. */
  53. public void wordToHtml(String docfile, String htmlfile) {
  54. ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
  55. try {
  56. app.setProperty("Visible", new Variant(false));
  57. Dispatch docs = app.getProperty("Documents").toDispatch();
  58. Dispatch doc = Dispatch.invoke(docs, "Open", Dispatch.Method, new Object[] { docfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
  59. Dispatch.invoke(doc, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(WORD_HTML) }, new int[1]);
  60. Variant f = new Variant(false);
  61. Dispatch.call(doc, "Close", f);
  62. } catch (Exception e) {
  63. e.printStackTrace();
  64. } finally {
  65. app.invoke("Quit", new Variant[] {});
  66. }
  67. }
  68. /**
  69. * WORD转HTML
  70. *
  71. * @param docfile
  72. * WORD文件全路径
  73. * @param htmlfile
  74. * 转换后HTML存放路径
  75. * @throws Throwable
  76. * add by duanql 2013-07-17
  77. */
  78. public void WordConverterHtml(String docfile, String htmlfile){
  79. try {
  80. InputStream input = new FileInputStream(docfile);
  81. HWPFDocument wordDocument = new HWPFDocument(input);
  82. WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
  83. wordToHtmlConverter.processDocument(wordDocument);
  84. Document htmlDocument = wordToHtmlConverter.getDocument();
  85. ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  86. DOMSource domSource = new DOMSource(htmlDocument);
  87. StreamResult streamResult = new StreamResult(outStream);
  88. TransformerFactory tf = TransformerFactory.newInstance();
  89. Transformer serializer = tf.newTransformer();
  90. serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
  91. serializer.setOutputProperty(OutputKeys.INDENT, "yes");
  92. serializer.setOutputProperty(OutputKeys.METHOD, "html");
  93. serializer.transform(domSource, streamResult);
  94. outStream.close();
  95. String content = new String(outStream.toByteArray(), "UTF-8");
  96. stringToFile(content,htmlfile);
  97. } catch (Exception e) {
  98. e.printStackTrace();
  99. }
  100. }
  101. /**
  102. * EXCEL转HTML
  103. *
  104. * @param xlsfile
  105. * EXCEL文件全路径
  106. * @param htmlfile
  107. * 转换后HTML存放路径
  108. */
  109. public void excelToHtml(String xlsfile, String htmlfile) {
  110. ActiveXComponent app = new ActiveXComponent("Excel.Application"); // 启动excel
  111. try {
  112. app.setProperty("Visible", new Variant(false));
  113. Dispatch excels = app.getProperty("Workbooks").toDispatch();
  114. Dispatch excel = Dispatch.invoke(excels, "Open", Dispatch.Method, new Object[] { xlsfile, new Variant(false), new Variant(true) }, new int[1]).toDispatch();
  115. Dispatch.invoke(excel, "SaveAs", Dispatch.Method, new Object[] { htmlfile, new Variant(EXCEL_HTML) }, new int[1]);
  116. Variant f = new Variant(false);
  117. Dispatch.call(excel, "Close", f);
  118. org.jeecgframework.core.util.LogUtil.info("wordtohtml转换成功");
  119. } catch (Exception e) {
  120. e.printStackTrace();
  121. } finally {
  122. app.invoke("Quit", new Variant[] {});
  123. }
  124. }
  125. /**
  126. * 读文件到字符串
  127. *
  128. * @param filename 要读的文件名称
  129. *
  130. */
  131. public String getInfo(String tmpFile) throws IOException {
  132. StringBuffer sbFile = null;
  133. try{
  134. FileInputStream fin = new FileInputStream(tmpFile);
  135. InputStreamReader in = null;
  136. char[] buffer = new char[4096];
  137. int len;
  138. sbFile = new StringBuffer();
  139. in = new InputStreamReader(fin,"gb2312");
  140. while ( (len = in.read(buffer)) != -1) {
  141. String s = new String(buffer, 0, len);
  142. sbFile.append(s);
  143. }
  144. }catch (IOException e4) {
  145. LogUtil.error(e4.toString());
  146. }
  147. return sbFile.toString();
  148. }
  149. /**
  150. * 字符串写入文件
  151. *
  152. * @param str 要写入的字符串
  153. * @param filename 要写入的文件名称
  154. *
  155. */
  156. public void stringToFile(String str,String filename){
  157. try
  158. {
  159. FileOutputStream fout = new FileOutputStream(filename);
  160. OutputStreamWriter out = null;
  161. out = new OutputStreamWriter(fout,"gb2312");
  162. out.write(str);
  163. out.close();
  164. }catch (IOException e4) {
  165. LogUtil.error(e4.toString());
  166. }
  167. }
  168. /**
  169. * 标签替换 针对于<input />类型标签
  170. *
  171. * @param sourceStr html源字符串
  172. * @param oldStr 要替换的标签字符串
  173. * @param newStr 替换后的标签内容
  174. *
  175. */
  176. public String regExReplace(String sourceStr,String oldStr,String newStr){
  177. java.util.regex.Pattern pattern;
  178. java.util.regex.Matcher matcher;
  179. String ls_comStr = oldStr+regEx_replace;
  180. String ls_returnStr="";
  181. try
  182. {
  183. pattern = Pattern.compile(ls_comStr,Pattern.CASE_INSENSITIVE);
  184. matcher = pattern.matcher(sourceStr);
  185. ls_returnStr = matcher.replaceAll(newStr);
  186. }catch (Exception e) {
  187. LogUtil.error(e.toString());
  188. }
  189. return ls_returnStr;
  190. }
  191. /**
  192. * 处理HTML
  193. *
  194. * @param htmlStr
  195. * 要处理的HTML
  196. */
  197. public String doHtml(String htmlStr) {
  198. java.util.regex.Pattern pattern;
  199. java.util.regex.Matcher matcher;
  200. try{
  201. pattern = Pattern.compile(regEx_style,Pattern.CASE_INSENSITIVE);
  202. matcher = pattern.matcher(htmlStr);
  203. htmlStr = matcher.replaceAll("");
  204. pattern = Pattern.compile(regEx_attr1,Pattern.CASE_INSENSITIVE);
  205. matcher = pattern.matcher(htmlStr);
  206. htmlStr = matcher.replaceAll("");
  207. pattern = Pattern.compile(regEx_attr2,Pattern.CASE_INSENSITIVE);
  208. matcher = pattern.matcher(htmlStr);
  209. htmlStr = matcher.replaceAll("");
  210. pattern = Pattern.compile(regEx_attr3,Pattern.CASE_INSENSITIVE);
  211. matcher = pattern.matcher(htmlStr);
  212. htmlStr = matcher.replaceAll(" ");
  213. pattern = Pattern.compile(regEx_attr4,Pattern.CASE_INSENSITIVE);
  214. matcher = pattern.matcher(htmlStr);
  215. htmlStr = matcher.replaceAll("");
  216. pattern = Pattern.compile(regEx_attr5,Pattern.CASE_INSENSITIVE);
  217. matcher = pattern.matcher(htmlStr);
  218. htmlStr = matcher.replaceAll("");
  219. // pattern = Pattern.compile(regEx_attr7,Pattern.CASE_INSENSITIVE);
  220. // matcher = pattern.matcher(htmlStr);
  221. // htmlStr = matcher.replaceAll("");
  222. pattern = Pattern.compile(regEx_attr8,Pattern.CASE_INSENSITIVE);
  223. matcher = pattern.matcher(htmlStr);
  224. htmlStr = matcher.replaceAll("");
  225. //include
  226. StringBuilder ls_include = new StringBuilder("");
  227. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/jquery/jquery-1.8.3.js\"></script>");
  228. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/dataformat.js\"></script>");
  229. ls_include.append("<link id=\"easyuiTheme\" rel=\"stylesheet\" href=\"plug-in/easyui/themes/default/easyui.css\" type=\"text/css\"></link>");
  230. ls_include.append("<link rel=\"stylesheet\" href=\"plug-in/easyui/themes/icon.css\" type=\"text/css\"></link>");
  231. ls_include.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"plug-in/accordion/css/accordion.css\"></link>");
  232. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/easyui/jquery.easyui.min.1.3.2.js\"></script>");
  233. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/easyui/locale/easyui-lang-zh_CN.js\"></script>");
  234. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/syUtil.js\"></script>");
  235. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/My97DatePicker/WdatePicker.js\"></script>");
  236. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/lhgDialog/lhgdialog.min.js\"></script>");
  237. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/curdtools.js\"></script>");
  238. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/easyuiextend.js\"></script>");
  239. ls_include.append("<link rel=\"stylesheet\" href=\"plug-in/Validform/css/style.css\" type=\"text/css\"/>");
  240. ls_include.append("<link rel=\"stylesheet\" href=\"plug-in/Validform/css/tablefrom.css\" type=\"text/css\"/>");
  241. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/js/Validform_v5.3.1_min.js\"></script>");
  242. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/js/Validform_Datatype.js\"></script>");
  243. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/js/datatype.js\"></script>");
  244. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/plugin/passwordStrength/passwordStrength-min.js\"></script>");
  245. ls_include.append("<script type=\"text/javascript\">$(function(){$(\"#formobj\").Validform({tiptype:4,btnSubmit:\"#btn_sub\",btnReset:\"#btn_reset\",ajaxPost:true,usePlugin:{passwordstrength:{minLen:6,maxLen:18,trigger:function(obj,error){if(error){obj.parent().next().find(\".Validform_checktip\").show();obj.find(\".passwordStrength\").hide();}else{$(\".passwordStrength\").show();obj.parent().next().find(\".Validform_checktip\").hide();}}}},callback:function(data){var win = frameElement.api.opener;if(data.success==true){frameElement.api.close();win.tip(data.msg);}else{if(data.responseText==''||data.responseText==undefined)$(\"#formobj\").html(data.msg);else $(\"#formobj\").html(data.responseText); return false;}win.reloadTable();}});});</script>");
  246. ls_include.append("<style>");
  247. ls_include.append("body{font-size:12px;}");
  248. ls_include.append("table{border: 1px solid #000000;padding:0; margin:0 auto;border-collapse: collapse;width:100%;align:right;}");
  249. ls_include.append("td {border: 1px solid #000000;background: #fff;font-size:12px;padding: 3px 3px 3px 8px;color: #000000;word-break: keep-all;}");
  250. ls_include.append("</style>\r\n<body");
  251. pattern = Pattern.compile("<body",Pattern.CASE_INSENSITIVE);
  252. matcher = pattern.matcher(htmlStr);
  253. htmlStr = matcher.replaceAll(ls_include.toString().replace("$", "\\$"));
  254. /* pattern = Pattern.compile("<p[^>]+>",Pattern.CASE_INSENSITIVE);
  255. matcher = pattern.matcher(htmlStr);
  256. htmlStr = matcher.replaceAll("");
  257. pattern = Pattern.compile("<\\/p>",Pattern.CASE_INSENSITIVE);
  258. matcher = pattern.matcher(htmlStr);
  259. htmlStr = matcher.replaceAll("");
  260. */
  261. //添加<form>语句
  262. String ls_form = "<form action=\"cgFormBuildController.do?saveOrUpdate\" id=\"formobj\" name=\"formobj\" method=\"post\">\r\n" +
  263. "<input type=\"hidden\" name=\"tableName\" value=\"\\${tableName?if_exists?html}\"\\/>\r\n" +
  264. "<input type=\"hidden\" name=\"id\" value=\"\\${id?if_exists?html}\"\\/>\r\n" +
  265. "<input type=\"hidden\" id=\"btn_sub\" class=\"btn_sub\"\\/>\r\n#{jform_hidden_field}<table";
  266. pattern = Pattern.compile("<table",Pattern.CASE_INSENSITIVE);
  267. matcher = pattern.matcher(htmlStr);
  268. htmlStr = matcher.replaceAll(ls_form);
  269. //添加</form>语句
  270. pattern = Pattern.compile("</table>",Pattern.CASE_INSENSITIVE);
  271. matcher = pattern.matcher(htmlStr);
  272. htmlStr = matcher.replaceAll("</table>\r\n</form>");
  273. /*
  274. //添加input语句
  275. pattern = Pattern.compile(regEx_attr6,Pattern.CASE_INSENSITIVE);
  276. matcher = pattern.matcher(htmlStr);
  277. StringBuffer sb = new StringBuffer();
  278. String thStr = "";
  279. String inputStr = "";
  280. boolean result = matcher.find();
  281. while(result) {
  282. thStr = matcher.group(1);
  283. // inputStr = "<input type=\"text\" name=\""+thStr+"\" value=\"\\${"+thStr+"?if_exists?html}\"\\/>";
  284. inputStr = "";
  285. if(fieldMap.get(thStr)!=null){
  286. inputStr = FormHtmlUtil.getFormHTML(fieldMap.get(thStr));
  287. inputStr +="<span class=\"Validform_checktip\">&nbsp;</span>";
  288. }
  289. matcher.appendReplacement(sb, inputStr);
  290. result = matcher.find();
  291. }
  292. matcher.appendTail(sb);
  293. htmlStr = sb.toString();
  294. */
  295. }catch(Exception e) {
  296. LogUtil.error(e.getMessage());
  297. }
  298. return htmlStr;
  299. }
  300. /**
  301. * 处理HTML poi转换生成的html
  302. *
  303. * @param htmlStr 要处理的HTML
  304. *
  305. * add by Duanql 2013-07-22
  306. */
  307. public String doPoiHtml(String htmlStr) {
  308. java.util.regex.Pattern pattern;
  309. java.util.regex.Matcher matcher;
  310. //清除HTML标签匹配内容
  311. String regEx_poi1 = "<meta[^>]+>";
  312. String regEx_poi2 = "<[\\s]*?(style)[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?(style)[\\s]*?>";
  313. String regEx_poi3 = "[\\s]?(class|lang)=([^?(\\s|>)]+)";
  314. try{
  315. pattern = Pattern.compile(regEx_poi1,Pattern.CASE_INSENSITIVE);
  316. matcher = pattern.matcher(htmlStr);
  317. htmlStr = matcher.replaceAll("");
  318. pattern = Pattern.compile(regEx_poi2,Pattern.CASE_INSENSITIVE);
  319. matcher = pattern.matcher(htmlStr);
  320. htmlStr = matcher.replaceAll("");
  321. pattern = Pattern.compile(regEx_poi3,Pattern.CASE_INSENSITIVE);
  322. matcher = pattern.matcher(htmlStr);
  323. htmlStr = matcher.replaceAll("");
  324. pattern = Pattern.compile("b2\"",Pattern.CASE_INSENSITIVE);
  325. matcher = pattern.matcher(htmlStr);
  326. htmlStr = matcher.replaceAll("");
  327. pattern = Pattern.compile("<tbody>|</tbody>",Pattern.CASE_INSENSITIVE);
  328. matcher = pattern.matcher(htmlStr);
  329. htmlStr = matcher.replaceAll("");
  330. //include
  331. StringBuilder ls_include = new StringBuilder("");
  332. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/jquery/jquery-1.8.3.js\"></script>");
  333. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/dataformat.js\"></script>");
  334. ls_include.append("<link id=\"easyuiTheme\" rel=\"stylesheet\" href=\"plug-in/easyui/themes/default/easyui.css\" type=\"text/css\"></link>");
  335. ls_include.append("<link rel=\"stylesheet\" href=\"plug-in/easyui/themes/icon.css\" type=\"text/css\"></link>");
  336. ls_include.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"plug-in/accordion/css/accordion.css\"></link>");
  337. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/easyui/jquery.easyui.min.1.3.2.js\"></script>");
  338. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/easyui/locale/easyui-lang-zh_CN.js\"></script>");
  339. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/syUtil.js\"></script>");
  340. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/My97DatePicker/WdatePicker.js\"></script>");
  341. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/lhgDialog/lhgdialog.min.js\"></script>");
  342. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/curdtools.js\"></script>");
  343. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/tools/easyuiextend.js\"></script>");
  344. ls_include.append("<link rel=\"stylesheet\" href=\"plug-in/Validform/css/style.css\" type=\"text/css\"/>");
  345. ls_include.append("<link rel=\"stylesheet\" href=\"plug-in/Validform/css/tablefrom.css\" type=\"text/css\"/>");
  346. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/js/Validform_v5.3.1_min.js\"></script>");
  347. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/js/Validform_Datatype.js\"></script>");
  348. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/js/datatype.js\"></script>");
  349. ls_include.append("<script type=\"text/javascript\" src=\"plug-in/Validform/plugin/passwordStrength/passwordStrength-min.js\"></script>");
  350. ls_include.append("<script type=\"text/javascript\">$(function(){$(\"#formobj\").Validform({tiptype:4,btnSubmit:\"#btn_sub\",btnReset:\"#btn_reset\",ajaxPost:true,usePlugin:{passwordstrength:{minLen:6,maxLen:18,trigger:function(obj,error){if(error){obj.parent().next().find(\".Validform_checktip\").show();obj.find(\".passwordStrength\").hide();}else{$(\".passwordStrength\").show();obj.parent().next().find(\".Validform_checktip\").hide();}}}},callback:function(data){var win = frameElement.api.opener;if(data.success==true){frameElement.api.close();win.tip(data.msg);}else{if(data.responseText==''||data.responseText==undefined)$(\"#formobj\").html(data.msg);else $(\"#formobj\").html(data.responseText); return false;}win.reloadTable();}});});</script>");
  351. ls_include.append("<style>");
  352. ls_include.append("body{font-size:12px;}");
  353. ls_include.append("table{border: 1px solid #000000;padding:0; margin:0 auto;border-collapse: collapse;width:100%;align:right;}");
  354. ls_include.append("td {border: 1px solid #000000;background: #fff;font-size:12px;padding: 3px 3px 3px 8px;color: #000000;word-break: keep-all;}");
  355. ls_include.append("</style>\r\n<body");
  356. pattern = Pattern.compile("<body",Pattern.CASE_INSENSITIVE);
  357. matcher = pattern.matcher(htmlStr);
  358. htmlStr = matcher.replaceAll(ls_include.toString().replace("$", "\\$"));
  359. /* pattern = Pattern.compile("<p[^>]+>",Pattern.CASE_INSENSITIVE);
  360. matcher = pattern.matcher(htmlStr);
  361. htmlStr = matcher.replaceAll("");
  362. pattern = Pattern.compile("<\\/p>",Pattern.CASE_INSENSITIVE);
  363. matcher = pattern.matcher(htmlStr);
  364. htmlStr = matcher.replaceAll("");
  365. */
  366. //添加<form>语句
  367. String ls_form = "<form action=\"cgFormBuildController.do?saveOrUpdate\" id=\"formobj\" name=\"formobj\" method=\"post\">\r\n" +
  368. "<input type=\"hidden\" name=\"tableName\" value=\"\\${tableName?if_exists?html}\"\\/>\r\n" +
  369. "<input type=\"hidden\" name=\"id\" value=\"\\${id?if_exists?html}\"\\/>\r\n" +
  370. "<input type=\"hidden\" id=\"btn_sub\" class=\"btn_sub\"\\/>\r\n<table";
  371. pattern = Pattern.compile("<table",Pattern.CASE_INSENSITIVE);
  372. matcher = pattern.matcher(htmlStr);
  373. htmlStr = matcher.replaceAll(ls_form);
  374. //添加</form>语句
  375. pattern = Pattern.compile("</table>",Pattern.CASE_INSENSITIVE);
  376. matcher = pattern.matcher(htmlStr);
  377. htmlStr = matcher.replaceAll("</table>\r\n</form>");
  378. /*
  379. //添加input语句
  380. pattern = Pattern.compile(regEx_attr6,Pattern.CASE_INSENSITIVE);
  381. matcher = pattern.matcher(htmlStr);
  382. StringBuffer sb = new StringBuffer();
  383. String thStr = "";
  384. String inputStr = "";
  385. boolean result = matcher.find();
  386. while(result) {
  387. thStr = matcher.group(1);
  388. // inputStr = "<input type=\"text\" name=\""+thStr+"\" value=\"\\${"+thStr+"?if_exists?html}\"\\/>";
  389. inputStr = "";
  390. if(fieldMap.get(thStr)!=null){
  391. inputStr = FormHtmlUtil.getFormHTML(fieldMap.get(thStr));
  392. inputStr +="<span class=\"Validform_checktip\">&nbsp;</span>";
  393. }
  394. matcher.appendReplacement(sb, inputStr);
  395. result = matcher.find();
  396. }
  397. matcher.appendTail(sb);
  398. htmlStr = sb.toString();
  399. */
  400. }catch(Exception e) {
  401. LogUtil.error(e.getMessage());
  402. }
  403. return htmlStr;
  404. }
  405. public static void main(String[] args) {
  406. try{
  407. OfficeHtmlUtil wordtohtml = new OfficeHtmlUtil();
  408. // wordtohtml.wordToHtml("D://jeecg//qjd.doc", "D://jeecg//test.html");
  409. wordtohtml.WordConverterHtml("D://jeecg//qjd.doc", "D://jeecg//test.html");
  410. String htmlStr = wordtohtml.getInfo("D://jeecg//test.html");
  411. htmlStr = wordtohtml.doPoiHtml(htmlStr);
  412. wordtohtml.stringToFile(htmlStr,"D://jeecg//tt.html");
  413. }catch (IOException e4) {}
  414. }
  415. }