簡體   English   中英

read .pptx導致java.lang.ClassNotFoundException

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

在這個問題中,有人遇到了類似的問題:我想讀取.pptx文件的內容(只有文本),但只能使用.ppt文件。 所以我嘗試用接受的答案來解決它,但我得到了這個異常: java.lang.ClassNotFoundException: org.apache.poi.hslf.model.TextPainter$Key

我使用了這個頁面中的例子(在接受的答案中提出了),所以我不知道為什么它不起作用。 我的代碼:

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