- 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 = new ArrayList<Object>();
- data.add("1;add new grammer");
- data.add("2;support insert table");
- data.add("3;support more style");
- TableRenderData tables = new TableRenderData(headers, data,"",2017);
- Map<String, Object> datas = new HashMap<String, Object>();
- datas.put("logo", new PictureRenderData(600,480,"D:\\test\\1.jpg"));
- datas.put("title", new TextRenderData("9d55b8", "Deeply in love with the things you love,\\n just deepoove."));
- datas.put("changeLog",tables);
- datas.put("website", "http://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 voidModule2Word(Map datas,String moduleFileName,String docSavedName) throws IOException{
- XWPFTemplate doc = XWPFTemplate
- .create(Global.getConfig("bizz.modulepath")+moduleFileName);
- RenderAPI.render(doc, datas);
- File file =newFile(Global.getConfig("bizz.docpath")+docSavedName);
- if(file.exists()){
- file.delete();
- }
- FileOutputStream out =newFileOutputStream("D:\\test\\out.docx");
- doc.write(out);
- out.flush();
- out.close();
- }
- }
来源: http://www.bubuko.com/infodetail-2054531.html