java获取ppt备注,Java 添加、修改、读取、删除PPT备注

概述

幻灯片中的备注信息是只提供给幻灯片演讲者观看的特定内容,在演讲者放映幻灯片时,备注信息可给演讲者提供讲解思路,起到辅助讲解的作用。本文将通过Java程序来演示如何操作PPT幻灯片中的备注信息,要点包括:

添加备注信息

修改备注信息

读取备注信息

删除备注信息

使用工具

Free Spire.Presentation for Java (免费版)

Jar文件获取及导入:

方法1:通过官网

a448eb9bfc788a42487917e602a4a54a.png

方法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();

}

}

备注添加效果:

87c18293f5853ef2b7b1973f0cbd7694.png

【示例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();

}

}

备注修改效果:

fc8d24675576741cdd8fcc4018b8622e.png

【示例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();

}

}

备注信息读取结果:

2de98313f16a13f9e9aa27d9c763011f.png

【示例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();

}

}

备注信息删除效果:

c81fae86e62a68c2894ca7138d047e83.png

(本文完)

转载请注明出处!

原文出处:https://www.cnblogs.com/Yesi/p/11677338.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值