博客
关于我
Java 添加、修改、读取、删除PPT备注
阅读量:409 次
发布时间:2019-03-06

本文共 4312 字,大约阅读时间需要 14 分钟。

概述

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

  1. 添加备注信息
  2. 修改备注信息
  3. 读取备注信息
  4. 删除备注信息

 

使用工具

  • Free Spire.Presentation for Java (免费版)

Jar文件获取及导入:

方法1:通过官网文件包。下载后,解压文件,并将lib文件夹下的Spire.Presentation.jar文件导入到java程序。参考如下导入效果:

 

 

方法2:可通过仓库安装导入到maven项目,可参考


 

Java 代码示例

【示例1】添加备注信息

import com.spire.presentation.*;public class AddSpeakNotes {    public static void main(String[] args) throws Exception{        //加载PowerPoint文档        Presentation ppt = new Presentation();        ppt.loadFromFile("sample.pptx");        //获取第一张幻灯片        ISlide slide = ppt.getSlides().get(2);        //添加备注幻灯片到第一张幻灯片        NotesSlide notesSlide = slide.addNotesSlide();        //添加备注标题        ParagraphEx paragraph = new ParagraphEx();        String string = "备注:";        paragraph.setText(string);        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("AddSpeakerNotes.pptx", FileFormat.PPTX_2013);        ppt.dispose();    }}

备注添加效果:

【示例2】修改备注信息

import com.spire.presentation.*;public class ModifySpeakerNotes {    public static void main(String[] args) throws Exception{        //加载测试文档        Presentation ppt = new Presentation();        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.*;import java.io.FileWriter;public class ExtractSpeakerNotes {    public static void main(String[] args) throws Exception{        //加载测试文档        Presentation ppt = new Presentation();        ppt.loadFromFile("AddSpeakerNotes.pptx");        //获取指定幻灯片        ISlide slide = ppt.getSlides().get(2);        //获取幻灯片中的备注内容        StringBuilder builder = new StringBuilder();        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 class DeleteSpeakerNotes {    public static void main(String[] args)  throws Exception{        //加载测试文档        Presentation ppt = new Presentation();        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();    }}

备注信息删除效果:

 

(本文完)

转载请注明出处!

 

你可能感兴趣的文章
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>
multi swiper bug solution
查看>>
MySQL Binlog 日志监听与 Spring 集成实战
查看>>
MySQL binlog三种模式
查看>>
multi-angle cosine and sines
查看>>
Mysql Can't connect to MySQL server
查看>>
mysql case when 乱码_Mysql CASE WHEN 用法
查看>>
Multicast1
查看>>
mysql client library_MySQL数据库之zabbix3.x安装出现“configure: error: Not found mysqlclient library”的解决办法...
查看>>
MySQL Cluster 7.0.36 发布
查看>>
Multimodal Unsupervised Image-to-Image Translation多通道无监督图像翻译
查看>>
MySQL Cluster与MGR集群实战
查看>>
multipart/form-data与application/octet-stream的区别、application/x-www-form-urlencoded
查看>>
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>