简体   繁体   中英

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. 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

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文件添加到项目的类路径中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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