使用Apache POI将注释添加到Powerpoint幻灯片
问题描述:
是否可以使用Apache POI以编程方式创建的PowerPoint幻灯片添加注释?使用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);
正如你所看到的,似乎没有要创建音符添加到幻灯片对象所需要的对象的方式。
调用
Notes notesSheet = slide.getNotesSheet();
...返回null。
是否有另一种方法来创建必要的笔记对象,也许使用我没有找到的工厂类?
或者,有没有另一种方式来添加笔记到不涉及Note类的幻灯片?
答
问题是很古老,但我希望这个答案会帮助别人。使用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
[...]
这是行得通的。谢谢! – GBP 2016-09-26 11:31:38