是否可以使用Apache POI以编程方式创建的powerpoint幻灯片添加注释?
这是我到目前为止所拥有的
Slide slide = ppt.createSlide();
org.apache.poi.hslf.record.Notes notesRecord = new ???; // <--- No Public constructor
org.apache.poi.hslf.model.Notes noteModel = new org.apache.poi.hslf.model.Notes(notesRecord ); // <--- Only one constructor which takes a org.apache.poi.hslf.record.Notes
// hopefully make some notes
// add the notes to the slide
slide.setNotes(noteModel);
Run Code Online (Sandbox Code Playgroud)
如您所见,似乎没有办法创建向幻灯片对象添加注释所需的对象.
调用
Notes notesSheet = slide.getNotesSheet();
Run Code Online (Sandbox Code Playgroud)
...返回null.
有没有其他方法可以创建必要的注释对象,也许使用我没有找到的工厂类?
或者,是否有另一种方法可以向幻灯片中添加不涉及使用Note类的注释?
小智 8
这个问题很老,但我希望这个答案可以帮助别人.使用Apache POI 3.12,以下代码应将一些文本作为注释添加到幻灯片中:
// create a new empty slide show
XMLSlideShow ppt = new XMLSlideShow();
// add first slide
XSLFSlide slide = ppt.createSlide();
// get or create notes
XSLFNotes note = ppt.getNotesSlide(slide);
// insert text
for (XSLFTextShape shape : note.getPlaceholders()) {
if (shape.getTextType() == Placeholder.BODY) {
shape.setText("String");
break;
}
}
// save
[...]
Run Code Online (Sandbox Code Playgroud)