parent
829cdd0c9c
commit
c162285414
@ -0,0 +1,27 @@
|
||||
package com.supervision.springaidemo;
|
||||
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class WordRenderTest {
|
||||
public static void main(String[] args) throws FileNotFoundException {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("name", "张三");
|
||||
|
||||
// 加载本地模板文件
|
||||
InputStream inputStream = new FileInputStream("F:\\out\\测试模板.docx");
|
||||
|
||||
// 渲染模板
|
||||
XWPFTemplate template = XWPFTemplate.compile(inputStream).render(data);
|
||||
|
||||
try {
|
||||
// 写出到文件
|
||||
template.writeAndClose(new FileOutputStream("F:\\out\\output.docx"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue