在 Android 上向演示文稿添加矩形

向幻灯片添加矩形

要向演示文稿中选定的幻灯片添加一个简单矩形,请按照以下步骤操作:

在下面的示例中,我们已在演示文稿的第一张幻灯片上添加了一个简单矩形。

// 实例化表示 PPTX 的 Presentation 类
Presentation pres = new Presentation();
try {
    // 获取第一张幻灯片
    ISlide sld = pres.getSlides().get_Item(0);

    // 添加椭圆类型的 AutoShape
    IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 50);

    // 将 PPTX 文件写入磁盘
    pres.save("RecShp1.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

向幻灯片添加格式化矩形

要向幻灯片添加格式化矩形,请按照以下步骤操作:

上述步骤已在下面的示例中实现。

// 实例化表示 PPTX 的 Presentation 类
Presentation pres = new Presentation();
try {
    // 获取第一张幻灯片
    ISlide sld = pres.getSlides().get_Item(0);

    // 添加椭圆类型的 AutoShape
    IShape shp = sld.getShapes().addAutoShape(ShapeType.Rectangle, 50, 150, 150, 50);

    // 为椭圆形状应用一些格式设置
    shp.getFillFormat().setFillType(FillType.Solid);
    shp.getFillFormat().getSolidFillColor().setColor(Color.GRAY);

    // 为椭圆的线条应用一些格式设置
    shp.getLineFormat().getFillFormat().setFillType(FillType.Solid);
    shp.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
    shp.getLineFormat().setWidth(5);

    // 将 PPTX 文件写入磁盘
    pres.save("RecShp2.pptx", SaveFormat.Pptx);
} finally {
    if (pres != null) pres.dispose();
}

常见问题

如何添加带圆角的矩形?

使用圆角 shape type 并在形状属性中调整角半径;也可以通过几何调整对每个角单独进行圆化。

如何使用图像(纹理)填充矩形?

选择图片 fill type,提供图像源,并配置 stretching/tiling modes

矩形可以具有阴影和发光效果吗?

可以。Outer/inner shadow, glow, and soft edges 均可使用,并提供可调参数。

我可以将矩形变成带超链接的按钮吗?

可以。为形状点击分配超链接 Assign a hyperlink(跳转到幻灯片、文件、网页地址或电子邮件)。

如何防止矩形被移动或修改?

Use shape locks:可以禁止移动、调整大小、选择或文本编辑,以保持布局不变。

我能将矩形转换为光栅图像或 SVG 吗?

可以。您可以使用 render the shape 将形状渲染为指定大小/比例的图像,或使用 export it as SVG 导出为 SVG 以供矢量使用。

如何快速获取矩形在考虑主题和继承情况下的实际(有效)属性?

Use the shape’s effective properties:API 返回计算后的值,已考虑主题样式、布局和本地设置,简化格式分析。