Java读取pptx文件

2022-03-11 00:00:00 powerpoint java

有没有人能帮我用java阅读pptx文件?我希望能用Apache POI来阅读这个文件,本教程我已经搜索过了,但是我找不到它,我已经用这个代码成功地读取了ppt文件:

try {
    FileInputStream fis = new FileInputStream(file);
    fs = new POIFSFileSystem(fis);
    HSLFSlideShow show = new HSLFSlideShow(fs);
    SlideShow ss = new SlideShow(show);
    Slide[] slides=ss.getSlides();
    for (int x = 0; x < slides.length; x++) {
        System.out.println("Slide = " + (x + 1) + " :" + slides[x].getTitle());

        TextRun[] runs = slides[x].getTextRuns();
        for (int i = 0; i < runs.length; i++) {
            TextRun run = runs[i];
            if (run.getRunType() == TextHeaderAtom.TITLE_TYPE) {
                System.out.println("Slide title " + (i + 1) + ": " + run.getText());
            } else {
                System.out.println("Slide text run " + (i + 1) + ": "  + run.getRunType() + " : " + run.getText());
            }
        }
    }
} catch (IOException ioe) {
    ioe.printStackTrace();
}

有人能告诉我必须修改此代码的哪部分才能读取pptx文件吗?


解决方案

根据http://poi.apache.org/slideshow/index.html,您需要使用一组单独的类来读取OOXML.pptx文件。食谱中有示例代码:http://poi.apache.org/slideshow/xslf-cookbook.html

相关文章