这篇文章将介绍如何使用spire.presentation for java添加、读取和删除powerpoint幻灯片中的备注信息。
添加备注信息
import com.spire.presentation.*;
import java.io.filewriter;
public class speakernotes {
public static void main(string[] args) throws exception {
//加载powerpoint文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//获取第一张幻灯片
islide slide = ppt.getslides().get(0);
//添加备注幻灯片到第一张幻灯片
notesslide notesslide = slide.addnotesslide();
//添加备注标题
paragraphex paragraph = new paragraphex();
paragraph.settext("备注:");
notesslide.getnotestextframe().getparagraphs().append(paragraph);
//添加第一项备注
paragraph = new paragraphex();
paragraph.settext("第一项备注;");
notesslide.getnotestextframe().getparagraphs().append(paragraph);
notesslide.getnotestextframe().getparagraphs().get(1).setbullettype(textbullettype.numbered);
notesslide.getnotestextframe().getparagraphs().get(1).setbulletstyle(numberedbulletstyle.bullet_arabic_period);
//添加第二项备注
paragraph = new paragraphex();
paragraph.settext("第二项备注;");
notesslide.getnotestextframe().getparagraphs().append(paragraph);
notesslide.getnotestextframe().getparagraphs().get(2).setbullettype(textbullettype.numbered);
notesslide.getnotestextframe().getparagraphs().get(2).setbulletstyle(numberedbulletstyle.bullet_arabic_period);
//添加第三项备注
paragraph = new paragraphex();
paragraph.settext("第三项备注;");
notesslide.getnotestextframe().getparagraphs().append(paragraph);
notesslide.getnotestextframe().getparagraphs().get(3).setbullettype(textbullettype.numbered);
notesslide.getnotestextframe().getparagraphs().get(3).setbulletstyle(numberedbulletstyle.bullet_arabic_period);
//保存文档
ppt.savetofile("speakernotes.pptx", fileformat.pptx_2013);
}
}
读取备注信息
import com.spire.presentation.*;
import java.io.filewriter;
public class speakernotes {
public static void main(string[] args) throws exception {
//加载powerpoint文档
presentation ppt = new presentation();
ppt.loadfromfile("speakernotes.pptx");
//获取第一张幻灯片
islide slide = ppt.getslides().get(0);
//获取幻灯片中的备注内容
stringbuilder buffer = new stringbuilder();
string notes = slide.getnotesslide().getnotestextframe().gettext();
buffer.append(notes);
//保存到文本文档
filewriter writer = new filewriter("speakernotes.txt");
writer.write(buffer.tostring());
writer.flush();
writer.close();
}
}
删除备注信息
import com.spire.presentation.*;
import java.io.filewriter;
public class speakernotes {
public static void main(string[] args) throws exception {
//加载powerpoint文档
presentation ppt = new presentation();
ppt.loadfromfile("speakernotes.pptx");
//获取第一张幻灯片
islide slide = ppt.getslides().get(0);
//删除幻灯片中所有备注
slide.getnotesslide().getnotestextframe().getparagraphs().clear();
//保存文档
ppt.savetofile("deletespeakernotes.pptx", fileformat.pptx_2013);
}
}