{"id":1449,"date":"2021-10-21T17:30:45","date_gmt":"2021-10-21T09:30:45","guid":{"rendered":"http:\/\/diuut.com\/?p=1449"},"modified":"2021-10-21T17:30:45","modified_gmt":"2021-10-21T09:30:45","slug":"java%e6%89%b9%e9%87%8f%e7%94%9f%e6%88%90word%e6%96%87%e4%bb%b6poi_tl","status":"publish","type":"post","link":"https:\/\/diuut.com\/?p=1449","title":{"rendered":"JAVA\u6279\u91cf\u751f\u6210Word\u6587\u4ef6(Poi_tl)"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\"><p>\u9700\u6c42\uff1a<\/p><cite>\u9700\u8981\u5927\u6279\u91cf\u7684\u7ed9\u63a5\u53e3\u751f\u6210\u5ba1\u6279word\u6587\u4ef6\uff0c\u6bcf\u4e2a\u6587\u4ef6\u4e2d\u65f6\u95f4\u4e0e\u6807\u9898\u5404\u81ea\u72ec\u7acb<\/cite><\/blockquote>\n\n\n\n<p>\u8fd9\u91cc\u53ea\u9488\u5bf9word\u751f\u6210\uff0cExcel\u540e\u9762\u5de5\u4f5c\u7528\u5230\u7684\u518d\u66f4\u65b0<\/p>\n\n\n\n<p>poi-tl\uff08poi template language\uff09\u662fWord\u6a21\u677f\u5f15\u64ce\uff0c\u4f7f\u7528Word\u6a21\u677f\u548c\u6570\u636e\u521b\u5efa\u5f88\u68d2\u7684Word\u6587\u6863\u3002<a href=\"http:\/\/deepoove.com\/poi-tl\/#_why_poi_tl\">\u5b98\u7f51<\/a><\/p>\n\n\n\n<h5>Maven<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;dependency&gt;\n  &lt;groupId&gt;com.deepoove&lt;\/groupId&gt;\n  &lt;artifactId&gt;poi-tl&lt;\/artifactId&gt;\n  &lt;version&gt;1.10.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre><\/div>\n\n\n<p>\u8fd9\u91cc\u7684\u9700\u6c42\u53ea\u9700\u8981\u57fa\u4e8e\u4e00\u4e2a\u6a21\u677f\u5373\u53ef\u751f\u6210\u6240\u6709\u7684\u6587\u4ef6\uff0c\u6240\u4ee5\u53ea\u9700\u8981\u5728\u6a21\u677f\u4e2d\u5148\u51c6\u5907\u597d\u6240\u6709\u56fa\u5b9a\u7684\u4e1c\u897f\uff0c\u518d\u8865\u5145\u4e0a\u6807\u7b7e\u5373\u53ef\u8fdb\u884c\u586b\u5145\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img width=\"236\" height=\"92\" src=\"https:\/\/diuut.com\/wp-content\/uploads\/2021\/10\/image-3.png\" alt=\"\" class=\"wp-image-1451\"\/><figcaption>template.docx<\/figcaption><\/figure><\/div>\n\n\n\n<h5>\u751f\u6210\u4ee3\u7801\uff1a<\/h5>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: java; title: ; notranslate\" title=\"\">\npackage xyz.diuut;\n\nimport com.deepoove.poi.XWPFTemplate;\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.nio.file.Files;\nimport java.util.*;\n\/**\n * @Author Diuut\n * @Date 2021\/10\/21  16:18\n *\/\npublic class poi_tl {\n    public static void main(String&#91;] args) throws Exception {\n        List&lt;String&gt; apiList = getList(&quot;C:\\\\Users\\\\xxxx\\\\Desktop\\\\xxxx.txt&quot;);\n        for (int i = 0; i &lt; apiList.size(); i++) {\n            Map&lt;String, Object&gt; data = new HashMap&lt;&gt;();\n            data.put(&quot;apiName&quot;, apiList.get(i));\n            data.put(&quot;time&quot;, &quot;2021\u5e746\u670828\u65e5&quot;);\n            XWPFTemplate template = XWPFTemplate.compile(&quot;C:\\\\Users\\\\xxxx\\\\Desktop\\\\template.docx&quot;)\n                    .render(data);\n            FileOutputStream out;\n            out = new FileOutputStream(&quot;C:\\\\Users\\\\xxxx\\\\Desktop\\\\xxxx&quot;+i+&quot;.docx&quot;);\n            template.write(out);\n            System.out.println(&quot;\u5df2\u751f\u6210\uff1a&quot;+apiList.get(i));\n            out.flush();\n            out.close();\n            template.close();\n        }\n    }\n\n\n    \/**\n     * \u6839\u636e\u8def\u5f84\u6587\u4ef6\u751f\u6210\u5217\u8868\n     *\n     * @param path \u5730\u5740\n     * @return\n     *\/\n    public static List&lt;String&gt; getList(String path) {\n        File listFile = new File(path);\n        List&lt;String&gt; urlList = new ArrayList&lt;String&gt;();\n        if (listFile.exists()) {\n            try {\n                urlList = Files.readAllLines(listFile.toPath());\n            } catch (IOException ex) {\n                ex.printStackTrace();\n            }\n            if (urlList.isEmpty()) {\n                System.out.println(&quot;\u8def\u5f84\u6587\u4ef6\u751f\u6210\u4e3a\u7a7a&quot;);\n                return null;\n            }\n        }\n        return urlList;\n    }\n}\n<\/pre><\/div>\n\n\n<p>\u6587\u4ef6\u540d\u53ef\u81ea\u5b9a\u4e49\u751f\u6210\uff0c\u6b64\u5904\u51c6\u5907\u597d\u7684\u5217\u8868\u6587\u4ef6\u662ftxt\u683c\u5f0f\uff0c\u6bcf\u4e00\u884c\u5404\u81ea\u72ec\u7acb\uff0c\u53ef\u4ee5\u7528uedit\u5de5\u5177\u8fdb\u884c\u683c\u5f0f\u5316\u751f\u6210\u83b7\u53d6\uff0c\u65b9\u4fbf\u540e\u7eed\u5904\u7406\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42\uff1a \u9700\u8981\u5927\u6279\u91cf\u7684\u7ed9\u63a5\u53e3\u751f\u6210\u5ba1\u6279word\u6587\u4ef6\uff0c\u6bcf\u4e2a\u6587\u4ef6\u4e2d\u65f6\u95f4\u4e0e\u6807\u9898\u5404\u81ea\u72ec\u7acb \u8fd9\u91cc\u53ea\u9488\u5bf9word\u751f\u6210\uff0cExce<span class=\"more-button\"><a href=\"https:\/\/diuut.com\/?p=1449\" class=\"more-link\">view all . . .<span class=\"screen-reader-text\">JAVA\u6279\u91cf\u751f\u6210Word\u6587\u4ef6(Poi_tl)<\/span><\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":1169,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[2],"tags":[37,47],"_links":{"self":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1449"}],"collection":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1449"}],"version-history":[{"count":1,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1449\/revisions"}],"predecessor-version":[{"id":1452,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/posts\/1449\/revisions\/1452"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=\/wp\/v2\/media\/1169"}],"wp:attachment":[{"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/diuut.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}