如何在空白幻灯片中添加矩形

问题描述 投票:0回答:2

我正在使用 apache poi 来创建 ppt。 到目前为止,我可以在空白幻灯片中添加线条作为形状,但无法在其中添加矩形。我不知道如何继续在空白幻灯片中绘制矩形。

感谢您提前提供的所有建议。

编辑:

下面我发布了代码绘制线。我画了4条线,分别是上水平线、右垂直线、下水平线、左垂直线。它工作正常,但我需要绘制矩形而不是 4 条线。

//画正方形

        java.awt.geom.Path2D.Double upperHorizontalPath = new java.awt.geom.Path2D.Double();
        upperHorizontalPath.moveTo(20, 200);
        upperHorizontalPath.lineTo(230, 200);
        upperHorizontalPath.closePath();
        XSLFFreeformShape upperHorizontalShape = indexslide.createFreeform();
        upperHorizontalShape.setPath(upperHorizontalPath);
        upperHorizontalShape.setLineWidth(3);
        upperHorizontalShape.setLineColor(Color.BLACK);

        java.awt.geom.Path2D.Double rightVerticalPath = new java.awt.geom.Path2D.Double();
        rightVerticalPath.moveTo(230, 200);
        rightVerticalPath.lineTo(230, 300);
        rightVerticalPath.closePath();
        XSLFFreeformShape rightVerticalShape = indexslide.createFreeform();
        rightVerticalShape.setPath(rightVerticalPath);
        rightVerticalShape.setLineWidth(3);
        rightVerticalShape.setLineColor(Color.BLACK);

        java.awt.geom.Path2D.Double lowerHorizontalPath = new java.awt.geom.Path2D.Double();
        lowerHorizontalPath.moveTo(230, 300);
        lowerHorizontalPath.lineTo(20, 300);
        lowerHorizontalPath.closePath();
        XSLFFreeformShape lowerHorizontalShape = indexslide.createFreeform();
        lowerHorizontalShape.setPath(lowerHorizontalPath);
        lowerHorizontalShape.setLineWidth(3);
        lowerHorizontalShape.setLineColor(Color.BLACK);

        java.awt.geom.Path2D.Double leftVerticalPath = new java.awt.geom.Path2D.Double();
        leftVerticalPath.moveTo(20, 300);
        leftVerticalPath.lineTo(20, 200);
        leftVerticalPath.closePath();
        XSLFFreeformShape leftVerticalShape = indexslide.createFreeform();
        leftVerticalShape.setPath(leftVerticalPath);
        leftVerticalShape.setLineWidth(3);
        leftVerticalShape.setLineColor(Color.BLACK);
java apache-poi powerpoint
2个回答
0
投票

下面的代码将有助于在幻灯片中创建矩形形状。

XSLFTextBox lowerTextShape = locationSlide.createTextBox();

                        ((XSLFSimpleShape) lowerTextShape).setAnchor(new Rectangle2D.Double(10, 100, 600, 80));
                        ((XSLFSimpleShape) lowerTextShape).setAnchor(new java.awt.Rectangle(0, 385, 240, 110));
                        ((XSLFSimpleShape) lowerTextShape).setLineColor(Color.WHITE);
                        ((XSLFSimpleShape) lowerTextShape).setLineWidth(3);

0
投票

这是绘制矩形而不绘制单独线条的最少代码。

    XSLFSlideShow slideShow = new XMLSlideShow();
    XSLFSlide slide = slideShow.createSlide();

    XSLFAutoShape autoShape = slide.createAutoShape();
    autoShape.setShapeType(ShapeType.ROUND_RECT);
    autoShape.setFillColor(Color.BLUE);
    autoShape.setAnchor(new Rectangle(400, 400, 50, 50));

ROUND_1_RECT
枚举中,有一些方便的角点选项,例如
RECT
ShapeType
等。

© www.soinside.com 2019 - 2024. All rights reserved.