java获取ppt备注,Java 添加、修改、读取、删除PPT备注
概述
幻燈片中的備注信息是只提供給幻燈片演講者觀看的特定內容,在演講者放映幻燈片時,備注信息可給演講者提供講解思路,起到輔助講解的作用。本文將通過Java程序來演示如何操作PPT幻燈片中的備注信息,要點包括:
添加備注信息
修改備注信息
讀取備注信息
刪除備注信息
使用工具
Free Spire.Presentation for Java (免費版)
Jar文件獲取及導入:
方法1:通過官網
方法2:可通過
Java代碼示例
【示例1】添加備注信息
import com.spire.presentation.*;public classAddSpeakNotes {public static void main(String[] args) throwsException{//加載PowerPoint文檔
Presentation ppt = newPresentation();
ppt.loadFromFile("sample.pptx");//獲取第一張幻燈片
ISlide slide = ppt.getSlides().get(2);//添加備注幻燈片到第一張幻燈片
NotesSlide notesSlide =slide.addNotesSlide();//添加備注標題
ParagraphEx paragraph = newParagraphEx();
String string= "備注:";
paragraph.setText(string);
notesSlide.getNotesTextFrame().getParagraphs().append(paragraph);//添加第一項備注
paragraph = newParagraphEx();
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 = newParagraphEx();
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 = newParagraphEx();
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("AddSpeakerNotes.pptx", FileFormat.PPTX_2013);
ppt.dispose();
}
}
備注添加效果:
【示例2】修改備注信息
import com.spire.presentation.*;public classModifySpeakerNotes {public static void main(String[] args) throwsException{//加載測試文檔
Presentation ppt = newPresentation();
ppt.loadFromFile("AddSpeakerNotes.pptx");
//獲取指定幻燈片
ISlide slide = ppt.getSlides().get(2);//修改指定備注信息
slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(1).setText("新修改的備注信息");
slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(2).setAlignment(TextAlignmentType.CENTER);
slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(2).setBulletStyle(NumberedBulletStyle.BULLET_ROMAN_UC_PAREN_RIGHT);//保存文檔
ppt.saveToFile("modifySpeakerNotes.pptx",FileFormat.PPTX_2013);
ppt.dispose();
}
}
備注修改效果:
【示例3】讀取備注信息
import com.spire.presentation.*;importjava.io.FileWriter;public classExtractSpeakerNotes {public static void main(String[] args) throwsException{//加載測試文檔
Presentation ppt = newPresentation();
ppt.loadFromFile("AddSpeakerNotes.pptx");//獲取指定幻燈片
ISlide slide = ppt.getSlides().get(2);//獲取幻燈片中的備注內容
StringBuilder builder = newStringBuilder();
String notes=slide.getNotesSlide().getNotesTextFrame().getText();
builder.append(notes);//保存到文本文檔
FileWriter writer = new FileWriter("ExtractSpeakerNotes.txt");
writer.write(builder.toString());
writer.flush();
writer.close();
}
}
備注信息讀取結果:
【示例4】刪除備注信息
import com.spire.presentation.*;public classDeleteSpeakerNotes {public static void main(String[] args) throwsException{//加載測試文檔
Presentation ppt = newPresentation();
ppt.loadFromFile("test.pptx");//獲取指定幻燈片
ISlide slide = ppt.getSlides().get(2);//刪除備注信息
slide.getNotesSlide().getNotesTextFrame().getParagraphs().get(0).getTextRanges().clear();//刪除指定段落中的備注信息//slide.getNotesSlide().getNotesTextFrame().getParagraphs().clear();//刪除所有備注信息//保存文檔
ppt.saveToFile("deleteSpeakerNotes.pptx",FileFormat.PPTX_2013);
ppt.dispose();
}
}
備注信息刪除效果:
(本文完)
轉載請注明出處!
原文出處:https://www.cnblogs.com/Yesi/p/11677338.html
總結
以上是生活随笔為你收集整理的java获取ppt备注,Java 添加、修改、读取、删除PPT备注的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文件改日期 电梯卡dump_门禁电梯卡修
- 下一篇: 用DXP 软件快速画简单特定形状的PCB