效果展示
代码demo
public class DocxUtils {
private static void templateWrite(String filePath, String outFilePath, Map<String, String> params) throws Exception {
InputStream is = new FileInputStream(filePath);
XWPFDocument doc = new XWPFDocument(is);
Iterator<XWPFParagraph> paragraphsIterator = doc.getParagraphsIterator();
while (paragraphsIterator.hasNext()) {
replaceInPara(paragraphsIterator.next(), params);
}
OutputStream os = new FileOutputStream(outFilePath);
doc.write(os);
close(os);
close(is);
}
private static XWPFDocument replaceTemplateKeyFromParams(String templatePath, Map<String, String> params) throws Exception {
File tmpFile = ResourceUtils.getFile(templatePath);
InputStream inputStream = new FileInputStream(templatePath);
XWPFDocument xwpfDocument = new XWPFDocument(OPCPackage.open(tmpFile))