/**
*
* @param fileName 文件名称
* @param temp_path 临时路径
* @param moban_path 模版全路径
* @param data 数据
* @return moban_path
* @throws
*/
public String getMoban(String fileName,String temp_path,String moban_path,HashMap<String, String> data){
try {
write(moban_path, data, temp_path + fileName);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//返回文件
return temp_path + fileName;
}
private static void write(String template, HashMap<String, String> data,String destdoc) throws Exception {
Document doc = new Document(template);
DocumentBuilder builder = new DocumentBuilder(doc);
//定位到指定位置
for(Map.Entry<String, String> entry: data.entrySet())
{
String value = "";
if(!"null".equals(entry.getValue()+"")){
value = entry.getValue();
}
if(entry.getKey().indexOf("image")>-1){
builder.moveToBookmark(entry.getKey());
builder.insertImage(value, RelativeVerticalPosition.MARGIN,1, RelativeHorizontalPosition.MARGIN,130,280,280,WrapType.INLINE);
}else{
doc.getRange().replace(entry.getKey(), value, true, false);
}
}
//调用接口
doc.save(destdoc);
}
*需要jar包:aspose-16.4.jar