到目前为止,我只有一个有效的代码可以从ppt幻灯片笔记中检索文本
try {
FileInputStream is = new FileInputStream("C:\\sample\\test.ppt");
SlideShow ppt = new SlideShow(is);
Slide[] slide = ppt.getSlides();
for (int i = 0; i < slide.length; i++) {
System.out.println(i);
TextRun[] runs = slide[i].getNotesSheet().getTextRuns();
if (runs.length < 1) {
System.out.println("null");
} else {
for (TextRun run : runs) {
System.out.println(" > " + run.getText());
}
}
}
} catch (IOException ioe) {
}
但是,如何从pptx幻灯片笔记中检索文本?
经过不断的反复试验,找到了解决方案。
try {
FileInputStream fis = new FileInputStream("C:\\sample\\sample.pptx");
XMLSlideShow pptxshow = new XMLSlideShow(fis);
XSLFSlide[] slide2 = pptxshow.getSlides();
for (int i = 0; i < slide2.length; i++) {
System.out.println(i);
try {
XSLFNotes mynotes = slide2[i].getNotes();
for (XSLFShape shape : mynotes) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape txShape = (XSLFTextShape) shape;
for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
System.out.println(xslfParagraph.getText());
}
}
}
} catch (Exception e) {
}
}
} catch (IOException e) {
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句