我正在使用ApachePOI-XSLF(ooxml实现)从头开始绘制pptx,我很难找到好的文档和好的例子。图书馆也不容易理解而且不直接。 我想知道如何设置由XSLFConnectorShape连接的两个XSFLAutoShape形状的偏移量。
这是我现在的代码:
XMLSlideShow pptx = new XMLSlideShow();
XSLFSlide slide = pptx.createSlide();
XSLFAutoShape rectangle = slide.createAutoShape();
rectangle.setShapeType(ShapeType.RECT);
rectangle.setAnchor(new Rectangle2D.Double(100, 100, 100, 50));
rectangle.setLineColor(Color.blue);
rectangle.setFillColor(Color.lightGray);
XSLFAutoShape miniCircle = slide.createAutoShape();
miniCircle.setShapeType(ShapeType.ELLIPSE);
miniCircle.setAnchor(new Rectangle2D.Double(rectangle.getAnchor().getMaxX() + 200, rectangle.getAnchor().getCenterY()+50, 1, 1));
miniCircle.setLineColor(Color.yellow);
miniCircle.setFillColor(Color.yellow);
connect(slide, rectangle, miniCircle);
XSLFAutoShape anotherRectangle = slide.createAutoShape();
anotherRectangle.setShapeType(ShapeType.RECT);
anotherRectangle.setAnchor(new Rectangle2D.Double(miniCircle.getAnchor().getMaxX() + 200, 100, 100, 50));
anotherRectangle.setLineColor(Color.blue);
anotherRectangle.setFillColor(Color.lightGray);
connect(slide, miniCircle, anotherRectangle);
和连接方法:
public static void connect(XSLFSlide slide, XSLFAutoShape start, XSLFAutoShape end){
XSLFConnectorShape connector = slide.createConnector();
connector.setAnchor(new Rectangle2D.Double(start.getAnchor().getX() + 100, start.getAnchor().getCenterY(), 100, 1));
CTConnector ctConnector = (CTConnector)connector.getXmlObject();
ctConnector.getSpPr().getPrstGeom().setPrst(STShapeType.STRAIGHT_CONNECTOR_1);
CTNonVisualConnectorProperties cx = ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
// connection start
CTConnection stCxn = cx.addNewStCxn();
stCxn.setId(start.getShapeId());
// side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
stCxn.setIdx(3);
CTConnection endCxn = cx.addNewEndCxn();
endCxn.setId(end.getShapeId());
// side of the rectangle to attach the connector: left=1, bottom=2,right=3, top=4
endCxn.setIdx(3);
}
输出是: This is the output
但我想要这个: This is what I want
P.S。我编辑帖子是因为有人在没有理由的情况下竖起了帖子。我添加了更多信息,但仍然很复杂,因为库很复杂: - /。会再次介意帮助和竖起大拇指吗?如果你不能帮助至少不破坏我的声誉。我是认真的开发者。 TKX。