POI PPT上画连接符

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;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值