自动化文档生成及与Class.getMethod遇到的坑

一、自动化文档生成:

// 读取模版并生成文档
        XWPFTemplate template = XWPFTemplate.compile(templatePath).render(renderData);
        // 输出到文件系统FileOutputStream out;
        FileOutputStream out = null;
 
        try {
            out = new FileOutputStream(outputWordPath);
            template.write(out);
        } catch (IOException e) {
            LOG.error("输出文档文件出错 " + e.getMessage(),e);
        }finally {
            //忽略nulls和异常,关闭流  XWPFTemplate是poi特有的因此无法使用IOUtils关闭只能单独关闭
            IOUtils.closeQuietly(out);
//            out.close();
            template.close();
        }

其中renderData为Map,key为占位符,value为对应数据。而图片形式的替换将图片转为二进制byte封装进PictureRenderData存入value中。

 

猜你喜欢

转载自blog.csdn.net/as4589sd/article/details/104190918