我正在使用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);
答案 0 :(得分: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);