POI PPT上画连接符
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow();
XSLFSlide slide = slideShow.createSlide();
XSLFAutoShape shape1 = slide.createAutoShape();
shape1.setShapeType(ShapeType.RECT);
shape1.setFillColor(Color.BLUE);
shape1.setAnchor(new Rectangle(50, 50, 150, 50));
XSLFAutoShape shape2 = slide.createAutoShape();
shape2.setShapeType(ShapeType.RECT);
shape2.setFillColor(Color.BLUE);
shape2.setAnchor(new Rectangle(350, 200, 150, 50));
XSLFAutoShape shape3 = slide.createAutoShape();
shape3.setShapeType(ShapeType.RECT);
shape3.setFillColor(Color.BLUE);
shape3.setAnchor(new Rectangle(350, 50, 150, 50));
XSLFAutoShape shape4 = slide.createAutoShape();
shape4.setShapeType(ShapeType.RECT);
shape4.setFillColor(Color.BLUE);
shape4.setAnchor(new Rectangle(350, 110, 150, 50));
// create connector
XSLFConnectorShape connector1 = createConnector1(slide, shape1, shape2);
createConnector1(slide, shape1, shape3);
createConnector1(slide, shape1, shape4);
FileOutputStream out = new FileOutputStream("CreatePPTXConnectorShapes.pptx");
slideShow.write(out);
out.close();
}
private static XSLFConnectorShape createConnector1(XSLFSlide slide, XSLFAutoShape shape1, XSLFAutoShape shape2) {
XSLFConnectorShape connector = slide.createConnector();
connector.setShapeType(ShapeType.BENT_CONNECTOR_3);//指定弯曲连接符3的形状类型
connector.setAnchor(new Rectangle2D.Double(
shape1.getAnchor().getMaxX(), // x
shape1.getAnchor().getCenterY(),//y
shape2.getAnchor().getX()-shape1.getAnchor().getMaxX(),//宽
shape2.getAnchor().getCenterY()-shape1.getAnchor().getCenterY()//高
));
// now we fix the connecting points
CTConnector ctConnector = (CTConnector)connector.getXmlObject();
CTNonVisualConnectorProperties cx = ctConnector.getNvCxnSpPr().getCNvCxnSpPr();
CTConnection start = cx.addNewStCxn();
start.setId(shape1.getShapeId());
start.setIdx(3); // connecting point 2 is center of bottom edge
CTConnection end = cx.addNewEndCxn();
end.setId(shape2.getShapeId());
end.setIdx(1); // connecting point 0 is center of top edge
return connector;
}