java替换图片文字_Java poi 模板操作,替换文字、图片
cells = row.getTableCells();
for (XWPFTableCell cell : cells) {
for (Entrye : map.entrySet()) {
if (cell.getText().equals(e.getKey())) {
cell.removeParagraph(0);
cell.setText(e.getValue());
}
}
}
}
}
InputStream is = new FileInputStream("C:/Users/Administrator/Desktop/img1.png");
String blipId = document.addPictureData(is, CustomXWPFDocument.PICTURE_TYPE_PNG);
document.createPicture(blipId,document.getNextPicNameNumber(CustomXWPFDocument.PICTURE_TYPE_PNG), 500, 500);
FileOutputStream outStream = null;
outStream = new FileOutputStream(destPath);
document.write(outStream);
outStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void rwdoc (){
try{
File file = new File("C:/Users/Administrator/Desktop/aa.doc");
File file1 = new File("C:/Users/Administrator/Desktop/aa_11.doc");
InputStream istr = new FileInputStream(file);
HWPFDocument wDoc = new HWPFDocument(istr);
Range range = wDoc.getRange();
range.replaceText("${bjbh}", "11");
range.replaceText("${applyDepartmentPerson}", "22");
range.replaceText("${receive_year}", "33");
range.replaceText("${receive_month}", "44");
range.replaceText("${receive_day}", "55");
range.replaceText("${dealName}", "66");
OutputStream out = new FileOutputStream(file1);
wDoc.write(out);
wDoc.wait();
out.flush();out.close();
}catch (Exception e){
}
}
}
更多推荐
所有评论(0)