{"id":30181,"date":"2024-11-25T08:57:31","date_gmt":"2024-11-25T00:57:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/30181\/"},"modified":"2024-11-25T08:57:31","modified_gmt":"2024-11-25T00:57:31","slug":"andriod%e7%89%88%e6%b5%8f%e8%a7%88%e5%99%a8%e4%b8%8d%e6%94%af%e6%8c%81%e6%96%87%e6%a1%a3%e7%9b%b4%e6%8e%a5%e6%89%93%e5%bc%80%e7%9a%84%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/30181\/","title":{"rendered":"andriod\u7248\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u6587\u6863\u76f4\u63a5\u6253\u5f00\u7684\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<p><span>font<\/a>-size:14px&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp;<\/span><span style=\"font-size:12px\"> \u6700\u8fd1\u5f00\u53d1\u5fae\u4fe1\u4f01\u4e1a\u53f7\uff0c\u53d1\u73b0\u5fae\u4fe1andriod\u7248\u5185\u7f6e\u6d4f\u89c8\u5668\u5728\u6253\u5f00\u6587\u4ef6\u65b9\u9762\u6709\u95ee\u9898\uff0c\u4f46\u662fios\u7248\u6ca1\u6709\u95ee\u9898\uff0c\u539f\u56e0\u662fios\u7248\u4f7f\u7528\u7684\u662fsafari\u6d4f\u89c8\u5668 \u652f\u6301\u6587\u6863\u76f4\u63a5\u6253\u5f00\uff0c\u4f46\u662fandriod\u7248\u4f7f\u7528\u7684\u662f\u817e\u8baf\u6d4f\u89c8\u5668x5\u5185\u6838\uff0c\u4e0d\u77e5\u9053\u4ec0\u4e48\u539f\u56e0\u4e0d\u652f\u6301\uff0c\u53ef\u80fd\u662f\u96c6\u6210\u51fa\u73b0\u7684\u95ee\u9898\uff0c\u8fd9\u91cc\u63d0\u4f9b\u89e3\u51b3\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u540c\u6837\u9002\u7528\u624b\u673a\u6d4f\u89c8\u5668\u6216\u8005\u5b89\u5353\u5f00\u53d1\u3002\u901a\u8fc7\u6b64\u65b9\u6cd5\u53ef\u4ee5\u5728\u5fae\u4fe1\u4e0a\u5f00\u53d1\u81ea\u5df1\u7684\u7b2c\u4e09\u65b9\u5e94\u7528\uff0c\u6216\u8005\u89e3\u51b3\u81ea\u5df1\u7684\u9879\u76ee\u95ee\u9898\uff0c\u89e3\u51b3\u65b9\u6cd5\u53ca\u6838\u5fc3\u4ee3\u7801\u5982\u4e0b\uff1a<\/span><\/p>\n<p>&nbsp;&nbsp;&nbsp;&nbsp;<span style=\"font-size:18px\"> 1\u3001\u5224\u65ad\u6d4f\u89c8\u5668\u7c7b\u578b<\/span><\/p>\n<pre>&nbsp;HttpServletRequest&nbsp;req&nbsp;=&nbsp;ServletAction&nbsp;Context.getRequest();\r\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\r\nString&nbsp;userAgent=req.getHeader(\"User-Agent\");\/\/\u91cc\u9762\u5305\u542b\u4e86\u8bbe\u5907\u7c7b\u578b<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><span style=\"font-size:18px\">&nbsp;&nbsp;&nbsp;&nbsp;2\u3001IOS\u7248\u76f4\u63a5\u4f7f\u7528\u6d41\u8f93\u51fa<\/span><\/p>\n<p><span style=\"font-size:18px\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Andriod\u7248\u5229\u7528openoffice+jod\u8f6c\u6362\u6210html\uff0c\u7136\u540e\u5bf9html\u5185\u5bb9\u91cd\u65b0\u7f16\u8f91\uff0c\u6587\u4ef6\u4e2d\u6709\u7684\u5c06\u8def\u5f84\u6539\u4e3a\u7f51\u7edc\u8def\u5f84\u6216\u8005\u91c7\u7528\u6d41\u8f93\u51fa\uff08\u6539\u6210\u7f51\u7edc\u8def\u5f84\u6ce8\u610f\u7279\u6b8a\u7b26\u53f7\uff0c\u5982+\u53f7\u4f1a\u53d8\u6210\u7a7a\u683c\uff09<\/span><\/p>\n<pre>\/**\r\n\t&nbsp;*&nbsp;\u4eceOA\u4e0a\u6293\u53d6\u6587\u4ef6\r\n\t&nbsp;*&nbsp;author&nbsp;&nbsp;\u725f\u4e91\u98de\r\n\t&nbsp;*&nbsp;company&nbsp;\u6d77\u9890\u8f6f\u4ef6\u80a1\u4efd\u6709\u9650\u516c\u53f8\r\n\t&nbsp;*&nbsp;tel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15562579597\r\n\t&nbsp;*&nbsp;qq&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1147417467\r\n\t&nbsp;*&nbsp;team&nbsp;&nbsp;&nbsp;&nbsp;\u5ba2\u670d\u4ea7\u54c1\u4e2d\u5fc3\/\u4e8e\u6d0b\r\n\t&nbsp;*&nbsp;@return\r\n\t&nbsp;*\/\r\n\tpublic&nbsp;String&nbsp;getFileFromOa(){\t\r\n\t\t\r\n\t\tHttpServletRequest&nbsp;req&nbsp;=&nbsp;ServletActionContext.getRequest();\r\n\t\tString&nbsp;userAgent=req.getHeader(\"User-Agent\");\/\/\u91cc\u9762\u5305\u542b\u4e86\u8bbe\u5907\u7c7b\u578b\r\n\t\tif(-1!=userAgent.indexOf(\"iPhone\")){\r\n\t\t\t\/\/-----------------\/\/\r\n\t\t\t\/\/\u6b64\u65b9\u6cd5\u9700\u8981\u6d4f\u89c8\u5668\u81ea\u5df1\u80fd\u591f\u6253\u5f00\uff0cios\u53ef\u4ee5\u4f46\u662f\u5fae\u4fe1andriod\u7248\u5185\u7f6e\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\r\n\t\t\t\/\/-----------------\/\/\r\n\t\t\t\/\/\u5982\u679c\u662f\u82f9\u679c\u624b\u673a\r\n\t\t\t\/\/\u83b7\u5f97\u6587\u4ef6\u5730\u5740\r\n\t\t\t&nbsp;String&nbsp;fileUrl&nbsp;=&nbsp;ServletActionContext.getRequest().getParameter(\"fileUrl\");\r\n\t\t\t&nbsp;fileUrl.replaceAll(\"%20\",&nbsp;\"\\+\");\/\/\u8f6c\u6362\u52a0\u53f7\r\n\t\t\t&nbsp;String&nbsp;strURL&nbsp;=&nbsp;MessageUtil.oaUrl+fileUrl;\r\n\t\t\t&nbsp;String&nbsp;fileType=strURL.substring(strURL.lastIndexOf(\".\")+1,strURL.length());\r\n\t\t\t\/\/\u83b7\u5f97\u56fe\u7247\u7684\u6570\u636e\u6d41\r\n\t\t\ttry&nbsp;{\r\n\t\t\t\tURL&nbsp;oaUrl&nbsp;=&nbsp;new&nbsp;URL(strURL);\r\n\t\t\t\tHttpURLConnection&nbsp;httpConn&nbsp;=&nbsp;(HttpURLConnection)&nbsp;oaUrl.openConnection();\r\n\t\t\t\tInputStream&nbsp;in&nbsp;=&nbsp;httpConn.getInputStream();\r\n\t\t\t\t\/\/\u83b7\u53d6\u8f93\u51fa\u6d41\r\n\t\t\t\tHttpServletResponse&nbsp;response&nbsp;=&nbsp;ServletActionContext.getResponse();\r\n\t\t\t\treq.setCharacterEncoding(\"UTF-8\");\r\n\t\t\t\tresponse.setCharacterEncoding(\"UTF-8\");\r\n\t\t\t\tString&nbsp;name=fileUrl.substring(fileUrl.lastIndexOf(\"\/\")+1,&nbsp;fileUrl.length());\r\n\t\r\n\t\t\t\tresponse.setHeader(\"Content-Disposition\",&nbsp;&nbsp;\r\n\t\t\t\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"attachment;filename=\"&nbsp;+&nbsp;&nbsp;\r\n\t\t\t\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\t\t&nbsp;&nbsp;&nbsp;new&nbsp;String(&nbsp;(name&nbsp;).getBytes(),&nbsp;&nbsp;\r\n\t\t\t\t\t\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\"iso-8859-1\"));\r\n\t\t\t\tif(\"doc\".equals(fileType)||\"docx\".equals(fileType)){\r\n\t\t\t\t\tresponse.setContentType(\"application\/msword\");\r\n\t\t\t\t}else&nbsp;if(\"xls\".equals(fileType)||\"xlsx\".equals(fileType)){\r\n\t\t\t\t\tresponse.setContentType(\"application\/msexcel\");&nbsp;\r\n\t\t\t\t}else{\r\n\t\t\t\t\tresponse.setContentType(\"application\/\"+fileType);\r\n\t\t\t\t}\r\n\t\t\t\tOutputStream&nbsp;out&nbsp;=&nbsp;response.getOutputStream();\r\n\t\t\t\t\/\/\u8f93\u51fa\u56fe\u7247\u4fe1\u606f\r\n\t\t\t\tbyte[]&nbsp;bytes&nbsp;=&nbsp;new&nbsp;byte[1024];&nbsp;&nbsp;\r\n\t\t\t\tint&nbsp;cnt=0;&nbsp;&nbsp;\r\n\t\t\t\twhile&nbsp;((cnt=in.read(bytes,0,bytes.length))&nbsp;!=&nbsp;-1)&nbsp;{&nbsp;&nbsp;\r\n\t\t\t\t\tout.write(bytes,&nbsp;0,&nbsp;cnt);&nbsp;&nbsp;\r\n\t\t\t\t}&nbsp;&nbsp;\r\n\t\t\t\tout.flush();\r\n\t\t\t\tout.close();\r\n\t\t\t\tin.close();\r\n\t\r\n\t\t\t}&nbsp;catch&nbsp;(MalformedURLException&nbsp;e)&nbsp;{\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn&nbsp;null;\r\n\t\t}else{\r\n\t\t\t\/\/\u5982\u679c\u975e\u82f9\u679c\u624b\u673a\uff0c\u81ea\u5df1\u5904\u7406\u6587\u6863\r\n\t\t\t\r\n\t\t\t\/\/\u83b7\u5f97\u6587\u4ef6\u5730\u5740\r\n\t\t\tString&nbsp;fileUrl&nbsp;=&nbsp;ServletActionContext.getRequest().getParameter(\"fileUrl\");\r\n\t\t\t\t\t\t\r\n\t\t\tfileUrl.replaceAll(\"%2B\",&nbsp;\"\\+\");\/\/\u8f6c\u6362\u52a0\u53f7\r\n\t\t\tString&nbsp;strURL&nbsp;=&nbsp;MessageUtil.oaUrl+fileUrl;\r\n\t\t\t\/\/\u5728\u672c\u5730\u5b58\u653eOA\u6587\u4ef6\uff0c\u7136\u540e\u8f6c\u6362\u6210html\uff0c\u518d\u5bf9\u6587\u6863\u4e2d\u7684\u56fe\u7247\u8def\u5f84\u8fdb\u884c\u4fee\u6539\uff0c\u6700\u540e\u8f93\u51fa\u5230\u9875\u9762\r\n\t\t\ttry&nbsp;{\r\n\t\t\t\tURL&nbsp;oaUrl&nbsp;=&nbsp;new&nbsp;URL(strURL);\r\n\t\t\t\tHttpURLConnection&nbsp;httpConn&nbsp;=&nbsp;(HttpURLConnection)&nbsp;oaUrl.openConnection();\r\n\t\t\t\tInputStream&nbsp;in&nbsp;=&nbsp;httpConn.getInputStream();\r\n\t\t\t\t\/\/\u83b7\u53d6\u8f93\u51fa\u6d41\r\n\t\t\t\tHttpServletResponse&nbsp;response&nbsp;=&nbsp;ServletActionContext.getResponse();\r\n\t\t\t\treq.setCharacterEncoding(\"UTF-8\");\r\n\t\t\t\tresponse.setCharacterEncoding(\"UTF-8\");\r\n\t\t\t\tString&nbsp;name=fileUrl.substring(fileUrl.lastIndexOf(\"\/\")+1,&nbsp;fileUrl.length());\r\n\t\t\t\t\r\n\t\t\t\t\/\/\u9996\u5148\u5224\u65ad\u672c\u5730\u662f\u5426\u5b58\u5728\r\n\t\t\t\tString&nbsp;path=req.getRealPath(\"\");\r\n\t\t\t\tpath=path.substring(0,&nbsp;path.lastIndexOf(\"\\\")+1);\r\n\t\t\t\tFile&nbsp;htmlFile=new&nbsp;File(path&nbsp;+&nbsp;&nbsp;\"OaFileToHtml\\\"+name+\".html\");\r\n\t\t\t\tif(!htmlFile.exists()){\r\n\t\t\t\t\t\/\/\u5224\u65ad\u6587\u4ef6\u5939\u662f\u5426\u5b58\u5728\uff0c\u521b\u5efa\u6587\u4ef6\u5939\r\n\t\t\t\t\tString&nbsp;oaFilePath=path&nbsp;+&nbsp;\"OaFile\";\/\/\u5b58\u653eOA\u6587\u6863\u7684\u6587\u4ef6\u5939\u8def\u5f84;\r\n\t\t\t\t\tFile&nbsp;oaFiles=new&nbsp;File(oaFilePath);\r\n\t\t\t\t\tif(!oaFiles.exists()){\r\n\t\t\t\t\t\t\/\/\u5982\u679c\u6587\u4ef6\u5939\u4e0d\u5b58\u5728\u521b\u5efa\u6587\u4ef6\u5939\r\n\t\t\t\t\t\toaFiles.mkdirs();\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\/\/\u5c06OA\u6d88\u606f\u5b58\u5165\u672c\u5730\r\n\t\t\t\t\tFile&nbsp;oafile=new&nbsp;File(oaFiles+&nbsp;File.separator&nbsp;+name);\r\n\t\t\t\t\tOutputStream&nbsp;out&nbsp;=&nbsp;new&nbsp;FileOutputStream(oafile);\r\n\t\t\t\t\t\/\/\u8f93\u51fa\u56fe\u7247\u4fe1\u606f\r\n\t\t\t\t\tbyte[]&nbsp;bytes&nbsp;=&nbsp;new&nbsp;byte[1024];&nbsp;&nbsp;\r\n\t\t\t\t\tint&nbsp;cnt=0;&nbsp;&nbsp;\r\n\t\t\t\t\twhile&nbsp;((cnt=in.read(bytes,0,bytes.length))&nbsp;!=&nbsp;-1)&nbsp;{&nbsp;&nbsp;\r\n\t\t\t\t\t\tout.write(bytes,&nbsp;0,&nbsp;cnt);&nbsp;&nbsp;\r\n\t\t\t\t\t}&nbsp;&nbsp;\r\n\t\t\t\t\tout.flush();\r\n\t\t\t\t\tout.close();\r\n\t\t\t\t\tin.close();\r\n\t\t\t\t\t\/\/\u8f6c\u6362\u6210html\r\n\t\t\t\t\tString&nbsp;htmlFilePath&nbsp;=path&nbsp;+&nbsp;\"OaFileToHtml\";\/\/OA\u6587\u4ef6\u8f6c\u6210html\u7684\u4f4d\u7f6e\r\n\t\t\t\t\tString&nbsp;htmlcontext=ConvertFileToHtml.toHtmlString(oafile,&nbsp;htmlFilePath);\r\n\t\t\t\t\treq.setAttribute(\"htmlcontext\",&nbsp;htmlcontext);\r\n\t\t\t\t}else{\r\n\t\t\t\t\t\/\/\u5df2\u7ecf\u5b58\u5728\u8f6c\u6362\u6210\u529f\u7684\u6587\u6863\r\n\t\t\t\t\tStringBuffer&nbsp;htmlSb&nbsp;=&nbsp;new&nbsp;StringBuffer();\r\n\t\t\t\t\ttry&nbsp;{\r\n\t\t\t\t\t\tBufferedReader&nbsp;br&nbsp;=&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(new&nbsp;FileInputStream(htmlFile),Charset.forName(\"gb2312\")));\r\n\t\t\t\t\t\twhile&nbsp;(br.ready())&nbsp;{\r\n\t\t\t\t\t\t\thtmlSb.append(br.readLine());\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tbr.close();\r\n\t\t\t\t\t}&nbsp;catch&nbsp;(FileNotFoundException&nbsp;e)&nbsp;{\r\n\t\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t\t}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{\r\n\t\t\t\t\t\te.printStackTrace();\r\n\t\t\t\t\t}\r\n\t\t\t\t\t\/\/&nbsp;HTML\u6587\u4ef6\u5b57\u7b26\u4e32\r\n\t\t\t\t\tString&nbsp;htmlStr&nbsp;=&nbsp;htmlSb.toString();\r\n\t\t\t\t\t\/\/System.out.println(\"htmlStr=\"&nbsp;+&nbsp;htmlStr);\r\n\t\t\t\t\t\/\/&nbsp;\u8fd4\u56de\u7ecf\u8fc7\u6e05\u6d01\u7684html\u6587\u672c\r\n\t\t\t\t\treq.setAttribute(\"htmlcontext\",&nbsp;ConvertFileToHtml.clearFormat(htmlStr,&nbsp;\"\"));\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t}&nbsp;catch&nbsp;(MalformedURLException&nbsp;e)&nbsp;{\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{\r\n\t\t\t\te.printStackTrace();\r\n\t\t\t}\r\n\t\t\treturn&nbsp;\"lookfile\";\r\n\t\t}\r\n\t\t\r\n\t}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-\u5c06word\u8f6c\u6362\u6210html\u6587\u4ef6\uff0c\u5e76\u8bfb\u53d6\u5185\u5bb9&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>\u6b64\u7c7b\u501f\u9274\u539f\u5730\u5740\u5e76\u4fee\u6539jadethao.iteye.com\/blog\/1817738<\/p>\n<pre>package&nbsp;com.haiyisoft.wx.util;\r\n\r\nimport&nbsp;java.io.BufferedReader;\r\nimport&nbsp;java.io.File;\r\nimport&nbsp;java.io.FileInputStream;\r\nimport&nbsp;java.io.FileNotFoundException;\r\nimport&nbsp;java.io.IOException;\r\nimport&nbsp;java.io.InputStreamReader;\r\nimport&nbsp;java.net.ConnectException;\r\nimport&nbsp;java.nio.charset.Charset;\r\nimport&nbsp;java.util.regex.Matcher;\r\nimport&nbsp;java.util.regex.Pattern;\r\n\r\nimport&nbsp;com.artofsolving.jodconverter.DocumentConverter;\r\nimport&nbsp;com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;\r\nimport&nbsp;com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;\r\nimport&nbsp;com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;\r\n\r\n\/**\r\n&nbsp;*&nbsp;*&nbsp;\u7aef\u53e3\u542f\u52a8\u547d\u4ee4\uff1a\r\n&nbsp;*&nbsp;soffice&nbsp;-headless&nbsp;-accept=\"socket,port=8100;urp;\r\n&nbsp;*\r\n&nbsp;*&nbsp;\r\n&nbsp;*&nbsp;author&nbsp;&nbsp;\u725f\u4e91\u98de\r\n&nbsp;*&nbsp;company&nbsp;\u6d77\u9890\u8f6f\u4ef6\u80a1\u4efd\u6709\u9650\u516c\u53f8\r\n&nbsp;*&nbsp;tel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15562579597\r\n&nbsp;*&nbsp;qq&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1147417467\r\n&nbsp;*&nbsp;team&nbsp;&nbsp;&nbsp;&nbsp;\u5ba2\u670d\u4ea7\u54c1\u4e2d\u5fc3\/\u4e8e\u6d0b\r\n&nbsp;*&nbsp;\r\n&nbsp;*\/\r\npublic&nbsp;class&nbsp;ConvertFileToHtml&nbsp;{\r\n\t\/**\r\n\t&nbsp;*&nbsp;\u5c06word\u6587\u6863\u8f6c\u6362\u6210html\u6587\u6863\r\n\t&nbsp;*&nbsp;@param&nbsp;docFile&nbsp;&nbsp;&nbsp;\u9700\u8981\u8f6c\u6362\u7684word\u6587\u6863\r\n\t&nbsp;*&nbsp;@param&nbsp;filepath&nbsp;&nbsp;\u8f6c\u6362\u4e4b\u540ehtml\u7684\u5b58\u653e\u8def\u5f84\r\n\t&nbsp;*&nbsp;@return&nbsp;\u8f6c\u6362\u4e4b\u540e\u7684html\u6587\u4ef6\r\n\t&nbsp;*\/\r\n\tpublic&nbsp;static&nbsp;File&nbsp;convert(File&nbsp;docFile,&nbsp;String&nbsp;filepath)&nbsp;{\r\n\r\n\t\t\/\/&nbsp;\u521b\u5efa\u4fdd\u5b58html\u7684\u6587\u4ef6\r\n\t\tString&nbsp;fileName=docFile.getName();\r\n\t\tFile&nbsp;htmlFile&nbsp;=&nbsp;new&nbsp;File(filepath&nbsp;+&nbsp;\"\/\"&nbsp;+&nbsp;fileName&nbsp;+&nbsp;\".html\");\r\n\t\t\/\/&nbsp;\u521b\u5efaOpenoffice\u8fde\u63a5\r\n\t\tOpenOfficeConnection&nbsp;con&nbsp;=&nbsp;new&nbsp;SocketOpenOfficeConnection(8100);\r\n\t\ttry&nbsp;{\r\n\t\t\t\/\/&nbsp;\u8fde\u63a5\r\n\t\t\tcon.connect();\r\n\t\t}&nbsp;catch&nbsp;(ConnectException&nbsp;e)&nbsp;{\r\n\t\t\tSystem.out.println(\"\u83b7\u53d6OpenOffice\u8fde\u63a5\u5931\u8d25...\");\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\t\r\n\t\t\/\/&nbsp;\u521b\u5efa\u8f6c\u6362\u5668\r\n\t\tDocumentConverter&nbsp;converter&nbsp;=&nbsp;new&nbsp;OpenOfficeDocumentConverter(con);\r\n\t\t\/\/&nbsp;\u8f6c\u6362\u6587\u6863\u95eehtml\r\n\t\tconverter.convert(docFile,&nbsp;htmlFile);\r\n\t\t\/\/&nbsp;\u5173\u95edopenoffice\u8fde\u63a5\r\n\t\tcon.disconnect();\r\n\t\treturn&nbsp;htmlFile;\r\n\t}\r\n\r\n\t\/**\r\n\t&nbsp;*&nbsp;\r\n\t&nbsp;*&nbsp;\u5c06word\u8f6c\u6362\u6210html\u6587\u4ef6\uff0c\u5e76\u4e14\u83b7\u53d6html\u6587\u4ef6\u4ee3\u7801\u3002\r\n\t&nbsp;*&nbsp;@param&nbsp;docFile&nbsp;&nbsp;\u9700\u8981\u8f6c\u6362\u7684\u6587\u6863\r\n\t&nbsp;*&nbsp;@param&nbsp;filepath&nbsp;&nbsp;\u6587\u6863\u4e2d\u56fe\u7247\u7684\u4fdd\u5b58\u4f4d\u7f6e\r\n\t&nbsp;*&nbsp;@return&nbsp;\u8f6c\u6362\u6210\u529f\u7684html\u4ee3\u7801\r\n\t&nbsp;*\/\r\n\tpublic&nbsp;static&nbsp;String&nbsp;toHtmlString(File&nbsp;docFile,&nbsp;String&nbsp;filepath)&nbsp;{\r\n\t\t\/\/&nbsp;\u8f6c\u6362word\u6587\u6863\r\n\t\tFile&nbsp;htmlFile&nbsp;=&nbsp;convert(docFile,&nbsp;filepath);\r\n\t\tSystem.out.println(htmlFile.getAbsolutePath());\r\n\t\t\/\/&nbsp;\u83b7\u53d6html\u6587\u4ef6\u6d41\r\n\t\tStringBuffer&nbsp;htmlSb&nbsp;=&nbsp;new&nbsp;StringBuffer();\r\n\t\ttry&nbsp;{\r\n\t\t\tBufferedReader&nbsp;br&nbsp;=&nbsp;new&nbsp;BufferedReader(new&nbsp;InputStreamReader(new&nbsp;FileInputStream(htmlFile),Charset.forName(\"gb2312\")));\r\n\t\t\twhile&nbsp;(br.ready())&nbsp;{\r\n\t\t\t\thtmlSb.append(br.readLine());\r\n\t\t\t}\r\n\t\t\tbr.close();\r\n\t\t\t\/\/&nbsp;\u5220\u9664\u4e34\u65f6\u6587\u4ef6\r\n\t\t\t\/\/htmlFile.delete();\r\n\t\t}&nbsp;catch&nbsp;(FileNotFoundException&nbsp;e)&nbsp;{\r\n\t\t\te.printStackTrace();\r\n\t\t}&nbsp;catch&nbsp;(IOException&nbsp;e)&nbsp;{\r\n\t\t\te.printStackTrace();\r\n\t\t}\r\n\t\t\/\/&nbsp;HTML\u6587\u4ef6\u5b57\u7b26\u4e32\r\n\t\tString&nbsp;htmlStr&nbsp;=&nbsp;htmlSb.toString();\r\n\t\t\/\/System.out.println(\"htmlStr=\"&nbsp;+&nbsp;htmlStr);\r\n\t\t\/\/&nbsp;\u8fd4\u56de\u7ecf\u8fc7\u6e05\u6d01\u7684html\u6587\u672c\r\n\t\treturn&nbsp;clearFormat(htmlStr,&nbsp;filepath);\r\n\t}\r\n\r\n\t\/**\r\n\t&nbsp;*&nbsp;\r\n\t&nbsp;*&nbsp;\u6e05\u9664\u4e00\u4e9b\u4e0d\u9700\u8981\u7684html\u6807\u8bb0\r\n\t*\/\r\n\r\n\tpublic&nbsp;static&nbsp;String&nbsp;clearFormat(String&nbsp;htmlStr,&nbsp;String&nbsp;docImgPath)&nbsp;{\r\n\r\n\t\t\/\/&nbsp;\u83b7\u53d6body\u5185\u5bb9\u7684\u6b63\u5219\r\n\t\tString&nbsp;bodyReg&nbsp;=&nbsp;\"\";\r\n\t\tPattern&nbsp;bodyPattern&nbsp;=&nbsp;Pattern.compile(bodyReg);\r\n\t\tMatcher&nbsp;bodyMatcher&nbsp;=&nbsp;bodyPattern.matcher(htmlStr);\r\n\t\tif&nbsp;(bodyMatcher.find())&nbsp;{\r\n\t\t\t\/\/&nbsp;\u83b7\u53d6BODY\u5185\u5bb9\uff0c\u5e76\u8f6c\u5316BODY\u6807\u7b7e\u4e3ap\r\n\t\t\thtmlStr&nbsp;=&nbsp;bodyMatcher.group().replaceFirst(\"\",&nbsp;\"\");\r\n\t\t}\r\n\r\n\t\t\/\/&nbsp;\u8c03\u6574\u56fe\u7247\u5730\u5740,\u8fd9\u91cc\u5c06\u56fe\u7247\u8def\u5f84\u6539\u4e3a\u7f51\u7edc\u8def\u5f84\r\n\t\t\r\n\t\thtmlStr&nbsp;=&nbsp;htmlStr.replaceAll(\"&lt;img  string htmlstr='htmlStr.substring(0,htmlStr.indexOf(\"action=***\"))+temp3+temp1.substring(temp1.indexOf(\".\"),&nbsp;temp1.length());' alt=\"andriod\u7248\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u6587\u6863\u76f4\u63a5\u6253\u5f00\u7684\u89e3\u51b3\u529e\u6cd5\" &gt;\u8f6c\u6362\u6210\u4fdd\u7559\u6837\u5f0f\r\n\t\t\/\/&nbsp;content&nbsp;=&nbsp;content.replaceAll(\"(&lt;p&gt;]*&amp;gt;.*?)()\",\r\n\t\t\/\/&nbsp;\"&lt;\/p&gt;&lt;p&gt;\");\r\n\t\t\/\/&nbsp;\u628a&lt;\/p&gt;&lt;p&gt;&lt;\/p&gt;\u8f6c\u6362\u6210\u5e76\u5220\u9664\u6837\u5f0f\r\n\t\thtmlStr&nbsp;=&nbsp;htmlStr.replaceAll(\"(&lt;p&gt;]*)(&amp;gt;.*?)()\",&nbsp;\"&lt;\/p&gt;&lt;p&gt;\");\r\n\t\t\/\/&nbsp;\u5220\u9664\u4e0d\u9700\u8981\u7684\u6807\u7b7e\r\n\t\thtmlStr&nbsp;=&nbsp;htmlStr.replaceAll(\"]*?&amp;gt;\",\"\");\r\n\t\t\/\/&nbsp;\u5220\u9664\u4e0d\u9700\u8981\u7684\u5c5e\u6027\r\n\t\thtmlStr&nbsp;=&nbsp;htmlStr.replaceAll(\"]*)(?:lang|LANG|class|CLASS|style|STYLE|size|SIZE|face|FACE|[ovwxpOVWXP]:\\w+)=(?:'[^']*'|\"\"[^\"\"]*\"\"|[^&amp;gt;]+)([^&amp;gt;]*)&amp;gt;\",\"\");\r\n\r\n\t\treturn&nbsp;htmlStr;\r\n\r\n\t}\r\n}&lt;\/p&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u3010\u76f8\u5173\u63a8\u8350\u3011<\/p>\n<p>1. <span><strong>\u7279\u522b\u63a8\u8350<\/strong><\/span>\uff1a<\/p>\n<p>2. <\/p>\n<p>3. <br \/>&nbsp;<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fandriod\u7248\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u6587\u6863\u76f4\u63a5\u6253\u5f00\u7684\u89e3\u51b3\u529e\u6cd5\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>font-size:14px&#8221;&gt;&nbsp;&nbsp;&nbsp;&nbsp; \u6700\u8fd1\u5f00\u53d1\u5fae\u4fe1\u4f01\u4e1a\u53f7\uff0c\u53d1\u73b0\u5fae\u4fe1andriod\u7248\u5185\u7f6e\u6d4f\u89c8\u5668\u5728\u6253\u5f00\u6587\u4ef6\u65b9\u9762\u6709\u95ee\u9898\uff0c\u4f46\u662fios\u7248\u6ca1\u6709\u95ee\u9898\uff0c\u539f\u56e0\u662fios\u7248\u4f7f\u7528\u7684\u662fsafari\u6d4f\u89c8\u5668 \u652f\u6301\u6587\u6863\u76f4\u63a5\u6253\u5f00\uff0c\u4f46\u662fandriod\u7248\u4f7f\u7528\u7684\u662f\u817e\u8baf\u6d4f\u89c8\u5668x5\u5185\u6838\uff0c\u4e0d\u77e5\u9053\u4ec0\u4e48\u539f\u56e0\u4e0d\u652f\u6301\uff0c\u53ef\u80fd\u662f\u96c6\u6210\u51fa\u73b0\u7684\u95ee\u9898\uff0c\u8fd9\u91cc\u63d0\u4f9b\u89e3\u51b3\u65b9\u6cd5\uff0c\u8fd9\u79cd\u65b9\u6cd5\u4e5f\u540c\u6837\u9002\u7528\u624b\u673a\u6d4f\u89c8\u5668\u6216\u8005\u5b89\u5353\u5f00\u53d1\u3002\u901a\u8fc7\u6b64\u65b9\u6cd5\u53ef\u4ee5\u5728\u5fae\u4fe1\u4e0a\u5f00\u53d1\u81ea\u5df1\u7684\u7b2c\u4e09\u65b9\u5e94\u7528\uff0c\u6216\u8005\u89e3\u51b3\u81ea\u5df1\u7684\u9879\u76ee\u95ee\u9898\uff0c\u89e3\u51b3\u65b9\u6cd5\u53ca\u6838\u5fc3\u4ee3\u7801\u5982\u4e0b\uff1a &nbsp;&nbsp;&nbsp;&nbsp; 1\u3001\u5224\u65ad\u6d4f\u89c8\u5668\u7c7b\u578b &nbsp;HttpServletRequest&nbsp;req&nbsp;=&nbsp;ServletAction&nbsp;Context.getRequest(); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; String&nbsp;userAgent=req.getHeader(&#8220;User-Agent&#8221;);\/\/\u91cc\u9762\u5305\u542b\u4e86\u8bbe\u5907\u7c7b\u578b \u767b\u5f55\u540e\u590d\u5236 &nbsp;&nbsp;&nbsp;&nbsp;2\u3001IOS\u7248\u76f4\u63a5\u4f7f\u7528\u6d41\u8f93\u51fa &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Andriod\u7248\u5229\u7528openoffice+jod\u8f6c\u6362\u6210html\uff0c\u7136\u540e\u5bf9html\u5185\u5bb9\u91cd\u65b0\u7f16\u8f91\uff0c\u6587\u4ef6\u4e2d\u6709\u7684\u5c06\u8def\u5f84\u6539\u4e3a\u7f51\u7edc\u8def\u5f84\u6216\u8005\u91c7\u7528\u6d41\u8f93\u51fa\uff08\u6539\u6210\u7f51\u7edc\u8def\u5f84\u6ce8\u610f\u7279\u6b8a\u7b26\u53f7\uff0c\u5982+\u53f7\u4f1a\u53d8\u6210\u7a7a\u683c\uff09 \/** &nbsp;*&nbsp;\u4eceOA\u4e0a\u6293\u53d6\u6587\u4ef6 &nbsp;*&nbsp;author&nbsp;&nbsp;\u725f\u4e91\u98de &nbsp;*&nbsp;company&nbsp;\u6d77\u9890\u8f6f\u4ef6\u80a1\u4efd\u6709\u9650\u516c\u53f8 &nbsp;*&nbsp;tel&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;15562579597 &nbsp;*&nbsp;qq&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1147417467 &nbsp;*&nbsp;team&nbsp;&nbsp;&nbsp;&nbsp;\u5ba2\u670d\u4ea7\u54c1\u4e2d\u5fc3\/\u4e8e\u6d0b &nbsp;*&nbsp;@return &nbsp;*\/ public&nbsp;String&nbsp;getFileFromOa(){ HttpServletRequest&nbsp;req&nbsp;=&nbsp;ServletActionContext.getRequest(); String&nbsp;userAgent=req.getHeader(&#8220;User-Agent&#8221;);\/\/\u91cc\u9762\u5305\u542b\u4e86\u8bbe\u5907\u7c7b\u578b if(-1!=userAgent.indexOf(&#8220;iPhone&#8221;)){ \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\/\/ \/\/\u6b64\u65b9\u6cd5\u9700\u8981\u6d4f\u89c8\u5668\u81ea\u5df1\u80fd\u591f\u6253\u5f00\uff0cios\u53ef\u4ee5\u4f46\u662f\u5fae\u4fe1andriod\u7248\u5185\u7f6e\u6d4f\u89c8\u5668\u4e0d\u652f\u6301 \/\/&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;\/\/ \/\/\u5982\u679c\u662f\u82f9\u679c\u624b\u673a \/\/\u83b7\u5f97\u6587\u4ef6\u5730\u5740 &nbsp;String&nbsp;fileUrl&nbsp;=&nbsp;ServletActionContext.getRequest().getParameter(&#8220;fileUrl&#8221;); &nbsp;fileUrl.replaceAll(&#8220;%20&#8221;,&nbsp;&#8220;\\+&#8221;);\/\/\u8f6c\u6362\u52a0\u53f7 &nbsp;String&nbsp;strURL&nbsp;=&nbsp;MessageUtil.oaUrl+fileUrl; &nbsp;String&nbsp;fileType=strURL.substring(strURL.lastIndexOf(&#8220;.&#8221;)+1,strURL.length()); \/\/\u83b7\u5f97\u56fe\u7247\u7684\u6570\u636e\u6d41 try&nbsp;{ URL&nbsp;oaUrl&nbsp;=&nbsp;new&nbsp;URL(strURL); HttpURLConnection&nbsp;httpConn&nbsp;=&nbsp;(HttpURLConnection)&nbsp;oaUrl.openConnection(); InputStream&nbsp;in&nbsp;=&nbsp;httpConn.getInputStream(); \/\/\u83b7\u53d6\u8f93\u51fa\u6d41 HttpServletResponse&nbsp;response&nbsp;=&nbsp;ServletActionContext.getResponse(); req.setCharacterEncoding(&#8220;UTF-8&#8221;); response.setCharacterEncoding(&#8220;UTF-8&#8221;); String&nbsp;name=fileUrl.substring(fileUrl.lastIndexOf(&#8220;\/&#8221;)+1,&nbsp;fileUrl.length()); response.setHeader(&#8220;Content-Disposition&#8221;,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;attachment;filename=&#8221;&nbsp;+&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;new&nbsp;String(&nbsp;(name&nbsp;).getBytes(),&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#8220;iso-8859-1&#8221;)); if(&#8220;doc&#8221;.equals(fileType)||&#8221;docx&#8221;.equals(fileType)){ response.setContentType(&#8220;application\/msword&#8221;); }else&nbsp;if(&#8220;xls&#8221;.equals(fileType)||&#8221;xlsx&#8221;.equals(fileType)){ response.setContentType(&#8220;application\/msexcel&#8221;);&nbsp; }else{ response.setContentType(&#8220;application\/&#8221;+fileType); } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-30181","post","type-post","status-publish","format-standard","hentry","category-19"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=30181"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/30181\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=30181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=30181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=30181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}