- Apache POI PPT 教程
- Apache POI PPT - 主页
- Apache POI PPT - 概览
- Apache POI PPT - Java API 风格
- Apache POI PPT - 安装
- Apache POI PPT - 类和方法
- Apache POI PPT -演示文稿
- Apache POI PPT - 幻灯片布局
- Apache POI PPT - 幻灯片管理
- Apache POI PPT - 图像
- Apache POI PPT - 创建超链接
- Apache POI PPT - 读取形状
- Apache POI PPT - 格式化文本
- Apache POI PPT - 合并
- Apache POI PPT - PPT 至图像
- Apache POI PPT 资源
- Apache POI PPT - 快速指南
- Apache POI PPT - 有用资源
- Apache POI PPT - 讨论
Apache POI PPT - 读取形状
你可以使用 XSLFShape 类的 getShapeName() 方法获取演示文稿中使用的形状数量。以下是读取演示文稿中形状的程序 −
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
public class ReadingShapes {
public static void main(String args[]) throws IOException {
//creating a slideshow
File file = new File("shapes.pptx");
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(file));
//get slides
List<XSLFSlide> slide = ppt.getSlides();
//getting the shapes in the presentation
System.out.println("Shapes in the presentation:");
for (int i = 0; i < slide.size(); i++){
List<XSLFShape> sh = slide.get(i).getShapes();
for (int j = 0; j < sh.size(); j++){
//name of the shape
System.out.println(sh.get(j).getShapeName());
}
}
FileOutputStream out = new FileOutputStream(file);
ppt.write(out);
out.close();
}
}
将上述 Java 代码另存为 ReadingShapes.java,然后从命令提示符对其进行编译和执行,如下所示 −
$javac ReadingShapes.java $java ReadingShapes
它将进行编译和执行,生成以下输出。
Shapes in the presentation: Rectangle 1 Oval 1 Isosceles Triangle 1
新添加的带有各种形状的幻灯片如下所示 −
广告