我有一个场景,我需要从pptx (source.pptx)复制几张幻灯片,并根据幻灯片中提供的演示文稿备注将其作为单独的pptx文件(output.pptx)下载。我正在使用apache poi来实现它。这是我的代码。
String filename = filepath+"\\source.pptx";
try {
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream(filename));
XMLSlideShow outputppt = new XMLSlideShow();
XSLFSlide[] slides = ppt.getSlides();
for (int i = 0; i < slides.length; i++) {
try {
XSLFNotes mynotes = slides[i].getNotes();
for (XSLFShape shape : mynotes) {
if (shape instanceof XSLFTextShape) {
XSLFTextShape txShape = (XSLFTextShape) shape;
for (XSLFTextParagraph xslfParagraph : txShape.getTextParagraphs()) {
if (xslfParagraph.getText().equals("NOTES1") || xslfParagraph.getText().equals("NOTES2")) {
outputppt.createSlide().importContent(slides[i]);
}
}
}
}
} catch (Exception e) {
}
}
FileOutputStream out = new FileOutputStream("output.pptx");
outputppt.write(out);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
当我打开创建的output.pptx时,我收到以下错误:"PowerPoint发现output.pptx中的内容有问题PowerPoint可以尝试修复演示文稿如果您信任此演示文稿的来源,请单击“修复”。“
单击repair后:"PowerPoint removed unreadable content in merged.pptx Repaired。您应该检查此提示,以确定是否有任何内容意外更改或删除“,我可以看到带有”单击添加标题“和”单击添加副标题“的空白幻灯片。
有什么建议可以解决这个问题吗?
发布于 2018-05-18 23:43:19
这段代码适用于我复制幻灯片内容、布局和注释。如果你想继续原来的问题,只需根据你的需要修改代码即可。我假设你简单地必须:
//从源幻灯片获取布局XSLFSlideLayout srcSlide.getSlideLayout= srcSlide.getSlideLayout();XSLFSlide XSLFSlideLayout= ppt .createSlide(defaultMaster.getLayout(layout.getType())) .importContent(srcSlide);XSLFNotes srcNotes = srcSlide.getNotes();XSLFNotes newNotes =ppt.getNotesSlide(新幻灯片);ppt
发布于 2015-04-14 19:57:26
在一些文本框为空的情况下,我也遇到了同样的错误。通过在创建幻灯片时始终在所有占位符中设置空白文本解决了此问题。
XSLFSlide slide = presentation.createSlide(slideMaster.getLayout(layout));
// remove any placeholder texts
for (XSLFTextShape ph : slide.getPlaceholders()) {
ph.clearText();
ph.setText("");
}
https://stackoverflow.com/questions/27792966
复制相似问题