ruoyi-tpl 文件模板打印后台

This commit is contained in:
lizhengwei 2026-01-06 15:20:08 +08:00
parent c9423283da
commit 3d47accfeb
3 changed files with 55 additions and 24 deletions

View File

@ -16,6 +16,10 @@
</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>

View File

@ -16,9 +16,10 @@ public class Main {
System.out.println("|_| \\_|_|\\___\\___|_____/ \\___/ \\___|");
//测试示例模板生成word
TestTemplate.buildTestDocx();
// TestTemplate.buildTestDocx();
TestTemplate2.buildTestDocx();
//测试示例模板生成xlsx
TestTemplate.buildTestXlsx();
// TestTemplate.buildTestXlsx();
}
}

View File

@ -24,32 +24,58 @@ public class TestTemplate2 {
//表格
List<Map<String, Object>> books = new ArrayList<>();
Map<String, Object> book1 = new HashMap<>();
book1.put("ys", "10");
book1.put("ks", "20");
book1.put("yllx", "宣纸");
book1.put("zl", "30");
book1.put("ss", "40");
book1.put("yf", "50");
book1.put("sfl", "60.00");
book1.put("fl", "70");
book1.put("hl", "80");
books.add(book1);
Map<String, Object> book2 = new HashMap<>();
book2.put("ys", "11");
book2.put("ks", "21");
book2.put("yllx", "");
book2.put("zl", "31");
book2.put("ss", "41");
book2.put("yf", "51");
book2.put("sfl", "61.00");
book2.put("fl", "71");
book2.put("hl", "81");
books.add(book2);
Map<String, Object> map1 = new HashMap<>();
map1.put("ys", "10");
map1.put("ks", "20");
map1.put("yllx", "宣纸");
map1.put("zl", "30");
map1.put("ss", "40");
map1.put("yf", "50");
map1.put("sfl", "60.00");
map1.put("fl", "70");
map1.put("hl", "80");
books.add(map1);
Map<String, Object> map2 = new HashMap<>();
map2.put("ys", "11");
map2.put("ks", "21");
map2.put("yllx", "");
map2.put("zl", "31");
map2.put("ss", "41");
map2.put("yf", "51");
map2.put("sfl", "61.00");
map2.put("fl", "71");
map2.put("hl", "81");
books.add(map2);
List<Map<String, Object>> books2 = new ArrayList<>();
Map<String, Object> map12 = new HashMap<>();
map12.put("ys", "101");
map12.put("ks", "201");
map12.put("yllx", "宣纸1");
map12.put("zl", "301");
map12.put("ss", "401");
map12.put("yf", "501");
map12.put("sfl", "60.001");
map12.put("fl", "701");
map12.put("hl", "801");
books2.add(map12);
Map<String, Object> map22 = new HashMap<>();
map22.put("ys", "111");
map22.put("ks", "211");
map22.put("yllx", "宣1");
map22.put("zl", "311");
map22.put("ss", "411");
map22.put("yf", "511");
map22.put("sfl", "61.001");
map22.put("fl", "711");
map22.put("hl", "811");
books2.add(map22);
//测试示例模板生成word
try (NiceDoc docx = new NiceDoc(path + "发印单-FYD202510000014-模板.docx")){
docx.pushLabels(labels);
docx.pushTable("books", books);
docx.pushTable("books2", books2);
//生成文档
docx.save(path, UUID.randomUUID() + ".docx");
} catch (IOException e) {