base64编码方式导出
如果你需要在word中添加图片,那你就在第一步制作模板时,加入一张图片占位,然后打开xml文档,可以看到如下的一片base64编码后的代码:
<w:binData w:name="wordml://03000001.png" xml:space="preserve">iVBORw0…(很省略很省略)…CC</w:binData>
只要将 base64 的代码替换成例如: ${image} ,如下:
<w:binData w:name="wordml://03000001.png" xml:space="preserve">${image}</w:binData>
这里要注意“>${image}<”这尖括号中间不能加任何其他的诸如空格,tab,换行等符号。
[详见]http://www.cnblogs.com/dyllove98/p/3181579.html
图片以URL方式存在模板中
String address=ServletActionContext.getServletContext().getRealPath("/");
String serverName = ServletActionContext.getRequest().getScheme()+"://"+ServletActionContext.getRequest().getServerName()+":"+ServletActionContext.getRequest().getServerPort()+ServletActionContext.getRequest().getContextPath()+"/";
byte[] pic=temployee.getEphoto();
String dir=address+"images/student/"+temployee.getEcode()+".jpg";
FileOutputStream fos = null;
fos = new FileOutputStream(dir);
if(pic==null){
dataMap.put("stuphoto",serverName+"images/student/default.jpg");
}else {
fos.write(pic);
dataMap.put("stuphoto",serverName+"images/student/"+temployee.getEcode()+".jpg");
}
fos.close();
[详见] http://blog.csdn.net/body13_13/article/details/7594214