程序员日报、周报不再愁!java通过freemarker自动生成doc文件!

需求

老板需要看程序员日报、周报,程序员就给他看?no,写份日报的时间 == 写10行有效的代码 。因此为节省时间,我们采用freemarker模板生成方式自动生成doc文件,然后定时发送邮件给老板,数据从数据库里读取,数据库早就批量插入你这个月所做的事情,然后每天生成的日报都不同。你一个月的工作量2天内就完成!

实现

//加载需要装填的模板
            Template template  = null;
            //加载模板文件
            configure.setClassForTemplateLoading(this.getClass(),"/com/yanhui/templates");
            //设置对象包装器
            configure.setObjectWrapper(new DefaultObjectWrapper());
            //设置异常处理器
            configure.setTemplateExceptionHandler(TemplateExceptionHandler.IGNORE_HANDLER);
            //定义Template对象,注意模板类型名字与downloadType要一致
            template= configure.getTemplate(downloadType + ".xml");
            //输出文档
            File outFile = new File(savePath);
            Writer out = null;
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"utf-8"));                                   
            template.process(dataMap,out);
            outFile.delete();

源码下载

链接:http://pan.baidu.com/s/1o87Agye 密码:z69p

全CSDN的丰(好)色(se)博客,这里有书本看不到的Java技术,电影院禁播的电影,欢迎关注QQ群494808400

你可能感兴趣的:(java工具,java,freemarker,程序员,周报,日报)