![](/img/trans.png)
[英]java.lang.ClassNotFoundException DexPathList . Causes?
[英]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.