|
@@ -28,7 +28,7 @@ public class WordUtil {
|
|
|
* @param fileName 要输出的文件路径
|
|
|
* @throws Exception 抛出的异常
|
|
|
*/
|
|
|
- public static void generateWord(Map<String, Object> dataMap, String templateName, String fileName) throws Exception {
|
|
|
+ public static void generateWord(Map<String, Object> dataMap, String templateName, String path, String fileName) throws Exception {
|
|
|
|
|
|
Configuration configuration = new Configuration(new Version("2.3.28"));
|
|
|
configuration.setDefaultEncoding("UTF-8");
|
|
@@ -39,8 +39,13 @@ public class WordUtil {
|
|
|
configuration.setClassForTemplateLoading(WordUtil.class, "/templates");
|
|
|
|
|
|
Template tem = configuration.getTemplate(templateName, "UTF-8");
|
|
|
+
|
|
|
+ File file = new File(path);
|
|
|
+ if (!file.exists()){
|
|
|
+ file.mkdirs();
|
|
|
+ }
|
|
|
|
|
|
- Writer out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(new File(fileName).toPath()), StandardCharsets.UTF_8));
|
|
|
+ Writer out = new BufferedWriter(new OutputStreamWriter(Files.newOutputStream(new File(path + fileName).toPath()), StandardCharsets.UTF_8));
|
|
|
|
|
|
tem.process(dataMap, out);
|
|
|
out.flush();
|