PowerPoint 幻灯片中的备注信息是为使用者提供便利而设置的,该信息只对使用者可见。本文将向大家详细阐述如何通过Spire.Presentation for Java添加、读取和删除 PowerPoint 幻灯片中的备注信息。
?
class="MsoNormal">使用工具:Spire.Presentation for Java 2.2.3(免费版)
?
注:安装后,注意在程序中添加引用Spire.Presentation.jar文件(下载安装后解压,然后引用jar包)
?
示例1—添加备注信息:
?
Java代码?import com.spire.presentation.*; public class AddNotes { public static void main(String[] args) throws Exception { //加载PowerPoint文档 Presentation ppt = new Presentation(); ppt.loadFromFile("C:\\Users\\Administrator\\Desktop\\222.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); } }?
?添加备注信息效果
示例2--读取信息备注:
?
?
Java代码?
import com.spire.presentation.ISlide; import com.spire.presentation.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(); } }
?
?读取文本效果:
?
示例3--删除备注信息:
Java代码
import com.spire.presentation.FileFormat; import com.spire.presentation.ISlide; import com.spire.presentation.Presentation; public class DeleteNotes { 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); } }
?
?
?删除备注信息效果:
?
?