简体   繁体   English

read .pptx导致java.lang.ClassNotFoundException

[英]read .pptx causes java.lang.ClassNotFoundException

In this question someone had a similar problem I have: I want to read the content of a .pptx file (only the text), but only got it work with .ppt files. 在这个问题中,有人遇到了类似的问题:我想读取.pptx文件的内容(只有文本),但只能使用.ppt文件。 So I tried to solve it with the accepted answer, but I got this exception: java.lang.ClassNotFoundException: org.apache.poi.hslf.model.TextPainter$Key 所以我尝试用接受的答案来解决它,但我得到了这个异常: java.lang.ClassNotFoundException: org.apache.poi.hslf.model.TextPainter$Key

I used the example from this page (which was suggested in the accepted answer) so I have no idea why it does not work. 我使用了这个页面中的例子(在接受的答案中提出了),所以我不知道为什么它不起作用。 My code: 我的代码:

public static String readPPTX(String path) throws FileNotFoundException, IOException{
    XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(path));
    String content = "";
    XSLFSlide[] slides = ppt.getSlides();
    for (XSLFSlide slide : slides){
        XSLFShape[] sh = slide.getShapes();
        for (int j = 0; j < sh.length; j++){
            if (sh[j] instanceof XSLFTextShape){
                XSLFTextShape shape = (XSLFTextShape)sh[j];
                content += shape.getText() + "\n";
            }
        }
    }
    return content;
}

解决此问题的方法是将poi-scratchpad-3.9.jar文件添加到项目的类路径中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM