最近项目需要,生成的数据需要按照word 模板去生成相应的word文档。差了几个资料。发现以下两个博客解决了项目上的需求。地址如下
Java中根据模板导出数据到word的解决方案
http://blog.csdn.net/myyate/article/details/2049701
另一个是
jsp结合Velocity依据Word模板文件产生对应的数据文件
http://blog.csdn.net/Matol/article/details/6052555
部署tomcat项目可以参考
http://www.ibm.com/developerworks/cn/java/j-velocity/#5
velocity vm 模板 根据word另存为 mht文件后。修改mht代码 生成vm文件即可
服务器部分代码如下:
public String execute() throws Exception {
ServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
String sjid = (String) request.getParameter("sjid");
dhjldVo = this.dhjlManager.get(sjid);
// 初始化并取得Velocity引擎
VelocityEngine ve = new VelocityEngine();
// 取得velocity的模版
// String fileDir = DhjlQueryAction.class.getResource("/template").getPath();
Properties properties = new Properties();
//System.out.println("fileDirfileDi~~~"+fileDir);
properties.setProperty(ve.FILE_RESOURCE_LOADER_PATH,"\\template\\");
//指定,如"D:/template",但记住只要指定到文件夹就行了
ve.init(properties); //初始化
//// 取得velocity的模版 如果有汉字 用 GBK 否则可能出现乱码
Template t = ve.getTemplate("hellovelocity.vm","GBK");//此处只要指明文件名就可以了.
// 取得velocity的上下文context
VelocityContext context = new VelocityContext();
// 把数据填入上下文
context.put("name", "潘");
context.put("date", (new Date()).toString());
// 为后面的展示,提前输入List数值
List temp = new ArrayList();
temp.add("1");
temp.add("2");
context.put("list", temp);
// 输出流 注释部分代码为 将流写入到服务器的文件
/* PrintWriter writer = new PrintWriter("E://单点登录.doc","UTF-8");
t.merge(context, writer);
writer.flush();
writer.close(); */
//此部分代码为 生产一个下载流 客户端页面会 弹出 另存为的对话框
response.setHeader("content-disposition", "attachment;filename=ldws.doc" );
response.setContentType("application/msword;");
response.setCharacterEncoding("GBK");
StringWriter writer =new StringWriter();
// 转换输出
t.merge(context, writer);
response.getOutputStream().print(writer.toString());
return null;
}
分享到:
相关推荐
本课程从velocity engine也就是velocity引擎开始, 先讲解velocity的基本使用以及基础语法 , 然后再讲解velocity 的进阶内容velocity Tools , 以及velocity作为web项目的视图改如何使用 , 每一部分都会有一个综合案例...
Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎Velocity模板引擎
JAVA的Velocity语法学习 内涵《Velocity_java开发指南》《Java的模板引擎Velocity初体验》 以及所必须的jar ,和大家一块学习,很好哦
Velocity模板解析,通过Velocity模板自动替换表达式中的变量
Java Velocity模板引擎,简单字符串生成 https://blog.csdn.net/a497785609/article/details/130007990
NULL 博文链接:https://huohu2005.iteye.com/blog/2040139
velocity-web模板工具, 参考:http://blog.csdn.net/nature_fly088/article/details/52497779 和http://www.ibm.com/developerworks/cn/java/j-lo-velocity1/
Velocity1.4java开发指南中文版 Velocity1.4模板使用指南中文版中文版
Jsp结合Velocity实现依据Word模板文件生成对应数据文件,操作非常灵活,方便。
velocity+itext的整合导出pdf
Java Velocity 项目生成器使用 Jave Velocity 模板构建前端 Web 应用程序的生成器。特征CSS 自动前缀带有 LiveReload 的内置预览服务器自动编译 CoffeeScript & Sass 自动 lint 你的脚本自动将图像内联到 css 文件...
NULL 博文链接:https://kingmxj.iteye.com/blog/371850
Spring Boot项目 自动生成数据表模板,包括:Mapper、Mapper.xml、Service、Controller、html 自定义模板生成
Velocity模板实例 Velocity模板实例 Velocity模板实例 Velocity模板实例
Velocity 是基于Java的模板引擎,广泛应用在阿里集 体各个子公司。Velocity模板适用于大量模板使用的场景,支持复杂的逻辑运算,包含 基本数据类型、变量赋值和函数等功能。Velocity.js 支持 Node.js 和浏览器环境。...
主要介绍了JAVA velocity模板引擎使用实例,需要的朋友可以参考下
Velocity实现模板
SpringBoot集成Mybatis,velocity模板