Java 有没有一种方法可以通过ApachePOI从给定的PowerPoint文件中准确地获取演讲者笔记?
我正在尝试使用ApachePOI将演讲者笔记从一个powerpoint传输到另一个powerpoint,但无法获得准确的传输 环顾四周后,我找不到很多资源。我确实找到了这个链接:,它在大多数情况下都有效。但是,当原始pptx中包含幻灯片母版等功能时,一些不属于演讲者备注的文本将被解释为演讲者备注Java 有没有一种方法可以通过ApachePOI从给定的PowerPoint文件中准确地获取演讲者笔记?,java,maven,apache-poi,powerpoint,Java,Maven,Apache Poi,Powerpoint,我正在尝试使用ApachePOI将演讲者笔记从一个powerpoint传输到另一个powerpoint,但无法获得准确的传输 环顾四周后,我找不到很多资源。我确实找到了这个链接:,它在大多数情况下都有效。但是,当原始pptx中包含幻灯片母版等功能时,一些不属于演讲者备注的文本将被解释为演讲者备注 XSLFNotes notes_src = slides_src[i].getNotes(); XSLFNotes notes_dst = ppt_dst.getNotesSlide(slides_ds
XSLFNotes notes_src = slides_src[i].getNotes();
XSLFNotes notes_dst = ppt_dst.getNotesSlide(slides_dst[i]);
这都在for循环中,其中i是迭代数。在这里,我得到了源的幻灯片I和目标文件中相应的幻灯片I
for (XSLFShape shape_src : notes_src) {
if (shape_src instanceof XSLFTextShape) {
XSLFTextShape txShape = (XSLFTextShape) shape_src;
for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
这是我从幻灯片上得到的文本。下面的if循环是我必须开始过滤掉一些“演讲者”笔记的地方,这些笔记实际上不是演讲者笔记(例如,幻灯片编号以某种方式被解释为笔记;还打印了这个版权符号)
简言之,不是演讲者笔记的东西会以“笔记”的形式出现。网上关于这个主题的资源不多;有人能帮忙吗?得到的是notes幻灯片。这些可能不仅包含注释的正文文本形状,还包含通过其他占位符(如页眉、页脚、日期时间和幻灯片编号)填充的文本形状。要确定所获得的文本形状的类型,可以从该形状获取占位符类型。这是
CTShape cTShape = (CTShape)shape.getXmlObject();
STPlaceholderType.Enum type = cTShape.getNvSpPr().getNvPr().getPh().getType();
然后只能得到STPlaceholderType.BODY
类型的文本形状
例如:
import java.io.FileInputStream;
import org.apache.poi.xslf.usermodel.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
import java.util.List;
public class PowerPointReadNotes {
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow(new FileInputStream("PowerPointHavingNotes.pptx"));
List<XSLFSlide> slides = slideShow.getSlides();
for (XSLFSlide slide : slides) {
XSLFNotes notes = slide.getNotes();
for (XSLFShape shape : notes) {
CTShape cTShape = (CTShape)shape.getXmlObject();
STPlaceholderType.Enum type = cTShape.getNvSpPr().getNvPr().getPh().getType();
System.out.println("type: " + type);
if (type == STPlaceholderType.BODY) { // get only shapes of type BODY
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
for (XSLFTextParagraph paragraph : textShape) {
System.out.println(paragraph.getText());
}
}
}
}
}
}
}
import java.io.FileInputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.Placeholder;
import java.util.List;
public class PowerPointReadNotesHL {
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow(new FileInputStream("PowerPointHavingNotes.pptx"));
List<XSLFSlide> slides = slideShow.getSlides();
for (XSLFSlide slide : slides) {
XSLFNotes notes = slide.getNotes();
for (XSLFShape shape : notes) {
Placeholder placeholder = shape.getPlaceholder();
System.out.println("placeholder: " + placeholder);
if (placeholder == Placeholder.BODY) { // get only shapes of type BODY
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
for (XSLFTextParagraph paragraph : textShape) {
System.out.println(paragraph.getText());
}
}
}
}
}
}
}
因此,不需要直接使用低级ooxml模式类
import java.io.FileInputStream;
import org.apache.poi.xslf.usermodel.*;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
import org.openxmlformats.schemas.presentationml.x2006.main.STPlaceholderType;
import java.util.List;
public class PowerPointReadNotes {
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow(new FileInputStream("PowerPointHavingNotes.pptx"));
List<XSLFSlide> slides = slideShow.getSlides();
for (XSLFSlide slide : slides) {
XSLFNotes notes = slide.getNotes();
for (XSLFShape shape : notes) {
CTShape cTShape = (CTShape)shape.getXmlObject();
STPlaceholderType.Enum type = cTShape.getNvSpPr().getNvPr().getPh().getType();
System.out.println("type: " + type);
if (type == STPlaceholderType.BODY) { // get only shapes of type BODY
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
for (XSLFTextParagraph paragraph : textShape) {
System.out.println(paragraph.getText());
}
}
}
}
}
}
}
import java.io.FileInputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.Placeholder;
import java.util.List;
public class PowerPointReadNotesHL {
public static void main(String[] args) throws Exception {
XMLSlideShow slideShow = new XMLSlideShow(new FileInputStream("PowerPointHavingNotes.pptx"));
List<XSLFSlide> slides = slideShow.getSlides();
for (XSLFSlide slide : slides) {
XSLFNotes notes = slide.getNotes();
for (XSLFShape shape : notes) {
Placeholder placeholder = shape.getPlaceholder();
System.out.println("placeholder: " + placeholder);
if (placeholder == Placeholder.BODY) { // get only shapes of type BODY
if (shape instanceof XSLFTextShape) {
XSLFTextShape textShape = (XSLFTextShape) shape;
for (XSLFTextParagraph paragraph : textShape) {
System.out.println(paragraph.getText());
}
}
}
}
}
}
}