首页 > 代码库 > 使用模板生成word文档
使用模板生成word文档
使用poi-tl根据模板生成word文档,在porm.xml中添加poi-tl依赖,直接上代码
import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Map; import com.deepoove.poi.XWPFTemplate; import com.deepoove.poi.render.RenderAPI; import com.thinkgem.jeesite.common.config.Global; public class WordModule { /*public static void main(String[] args) throws Exception { //构造数据 XWPFTemplate doc = XWPFTemplate .create("D:\\test\\2.docx"); List<RenderData> headers = new ArrayList<RenderData>(); headers.add(new TextRenderData("d0d0d0","number")); headers.add(new TextRenderData("d0d0d0", "content")); List<Object> data = http://www.mamicode.com/new ArrayListhttp://www.baidu.com"); //读取模板,进行渲染 RenderAPI.render(doc, datas); System.out.println(tables.getWidth()); //输出渲染后的文件 File file = new File("D:\\test\\out.docx"); if(file.exists()){ file.delete(); } FileOutputStream out = new FileOutputStream("D:\\test\\out.docx"); doc.write(out); out.flush(); out.close(); }*/ /** * data为添加文字或者图片对象 * 文字: * */ public static void Module2Word(Map<String ,Object> datas,String moduleFileName,String docSavedName) throws IOException{ XWPFTemplate doc = XWPFTemplate .create(Global.getConfig("bizz.modulepath")+moduleFileName); RenderAPI.render(doc, datas); File file = new File(Global.getConfig("bizz.docpath")+docSavedName); if(file.exists()){ file.delete(); } FileOutputStream out = new FileOutputStream("D:\\test\\out.docx"); doc.write(out); out.flush(); out.close(); } }
使用模板生成word文档
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。