验证中...
gistfile1.txt
Raw Copy
//替换占位符图片
Document doc = new Document(tempFile.getAbsolutePath()); // 载入模板
NodeCollection<?> shapeCollection = doc.getChildNodes(NodeType.SHAPE, true);
Node[] shapes = shapeCollection.toArray();// 序列化
for (Node node : shapes) {
Shape shape = (Shape) node;
if (shape.getShapeType() == ShapeType.IMAGE) {// 如果shape类型是ole类型
DocumentBuilder builder = new DocumentBuilder(doc);// 新建文档节点
builder.moveTo(shape);// 移动到图片位置 shape
@SuppressWarnings("unused")
double kleft = 0;
for (Section nodet : doc.getSections()) {
kleft = nodet.getPageSetup().getPageWidth() - nodet.getPageSetup().getLeftMargin() - nodet.getPageSetup().getRightMargin();
}
builder.insertImage(Base64Utils.decode(ewmstring), RelativeHorizontalPosition.PAGE, shape.getLeft() + shape.getWidth() + 15, RelativeVerticalPosition.PAGE, shape.getTop() + shape.getHeight() + 5, shape.getWidth(), shape.getHeight(), WrapType.NONE);
shape.remove();// 移除图形
}
}
//读取模板中的标签
BookmarkCollection bookmarkCollection = doc.getRange().getBookmarks();
//根据itemcode获取对应的公司名称
String itemname = templateDao.getItemnameByItemcode();
if(bookmarkCollection.getCount()> 0){
Bookmark bookmark = bookmarkCollection.get(0);
bookmark.setText(itemname);
}

Comment list( 0 )

You need to Sign in for post a comment

Help Search