1。word文件另存为mht格式的文件;
2。根据Velocity的语法动态化mht文件内容,产生相应的、动态化模型的vm文件;
3。输出流,依据动态化的数据,输出word文件。
相关项目源码,请查看我的下载资源 http://matol.download.csdn.net/
jsp源码:
VelocityEngine ve=new VelocityEngine(pro);
Template t = ve.getTemplate("info.vm","utf-8");
VelocityContext context = new VelocityContext();
context.put("info", "中石油吐哈油田");
context.put("cont", "lgoin");
context.put("phone", "13152870917");
List listMaps = new ArrayList();
Map<String,String> paramValues = null;
for(int i=0;i<2000;i++){
paramValues = new HashMap<String, String>();
paramValues.put("email","email"+i);
paramValues.put("zhenming","真名"+i);
paramValues.put("system","系统"+i);
paramValues.put("yunwei","运维"+i);
paramValues.put("name","用户"+i);
paramValues.put("pass","密码"+i);
paramValues.put("remark","备注"+i);
listMaps.add(paramValues);
}
context.put("listMaps", listMaps);
PrintWriter writer = new PrintWriter("E://单点登录.doc","UTF-8");
t.merge(context, writer);
writer.flush();
writer.close();
} catch (Exception e) {
out.println("Error ..."+e.getMessage());
}
long t2=System.currentTimeMillis(); //排序后取得当前时间
Calendar c=Calendar.getInstance();
c.setTimeInMillis(t2-t1);
out.println("Success ... 耗时: " + c.get(Calendar.MINUTE) + "分 " + c.get(Calendar.SECOND) + "秒 " + c.get(Calendar.MILLISECOND) + " 微秒");
%>
vm源码: