博客
关于我
Java 编辑PPT SmartArt图形
阅读量:414 次
发布时间:2019-03-06

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

本文介绍在Java程序中如何来编辑PPT幻灯片中已有的SmartArt图形,包括重置图形样式、颜色、添加/删除图形节点、编辑节点内容、添加超链接到节点(链接到网页、链接到指定幻灯片)等。在PPT中创建SmartArt图形、读取SmartArt图形可参考这篇里的方法。

工具:Free Spire.Presentation for Java 免费版,jar导入,参考如下方法:

方法1. 官网,解压,将lib文件夹下的 Spire.Presentation.jar 文件导入Java程序;

方法2. 在Maven程序中导入需要先配置pom.xml文件,如下:

com.e-iceblue
http://repo.e-iceblue.cn/repository/maven-public/
e-iceblue
spire.presentation.free
3.9.0

配置好后,导入jar。

 

Java示例

import com.spire.presentation.*;import com.spire.presentation.diagrams.*;public class ModifySmartArt {    public static void main(String[] args) throws Exception {        //加载PPT文档        Presentation ppt = new Presentation();        ppt.loadFromFile("sample.pptx");        //获取SmartArt图形        ISmartArt smartart = (ISmartArt) ppt.getSlides().get(0).getShapes().get(0);        //重置图形样式及颜色        smartart.setStyle(SmartArtStyleType.SUBTLE_EFFECT);        smartart.setColorStyle(SmartArtColorType.COLORFUL_ACCENT_COLORS_2_TO_3);        //获取SmartArt图形的节点集合        ISmartArtNodeCollection nodes = smartart.getNodes();        nodes.get(1).getTextFrame().setText("新修改的节点内容");//更改节点内容        nodes.get(1).getTextFrame().setAutofitType(TextAutofitType.SHAPE);//设置节点形状的文本自适应类型        //添加超链接到节点        nodes.get(2).setClick(new ClickHyperlink("https://www.baidu.com/"));//添加指向网页的超链接        nodes.get(3).setClick(new ClickHyperlink(ppt.getSlides().get(1)));//添加指向指定幻灯片的超链接        //添加节点        ISmartArtNode newnode = nodes.get(5).getChildNodes().addNode();        newnode.getTextFrame().setText("新添加的节点内容");        //nodes[0].ChildNodes[3].ChildNodes.RemoveNodeByPosition(0);//删除节点        //保存文档        ppt.saveToFile("output.pptx", FileFormat.PPTX_2013);        ppt.dispose();    }}

测试文档:

编辑结果如下,添加的超链接效果需要在幻灯片播放中查看:

 

(本文完)

 

转载地址:http://xdnkz.baihongyu.com/

你可能感兴趣的文章
mysql启动和关闭外键约束的方法(FOREIGN_KEY_CHECKS)
查看>>
Mysql启动失败解决过程
查看>>
MySQL启动失败:Can't start server: Bind on TCP/IP port
查看>>
mysql启动报错
查看>>
mysql启动报错The server quit without updating PID file几种解决办法
查看>>
mysql命令
查看>>
mysql命令==_mysql命令
查看>>
mysql命令和mysql的配置文件
查看>>
watch
查看>>
MySQL命令行操作的相关语法
查看>>
MySQL命令行登陆,远程登陆MySQL
查看>>
mysql命令:set sql_log_bin=on/off
查看>>
mySQL和Hive的区别
查看>>
MySQL和Java数据类型对应
查看>>
mysql和oorcale日期区间查询【含左右区间问题】
查看>>
MYSQL和ORACLE的一些操作区别
查看>>
mysql和redis之间互相备份
查看>>
MySQL和SQL入门
查看>>
mysql在centos下用命令批量导入报错_Variable ‘character_set_client‘ can‘t be set to the value of ‘---linux工作笔记042
查看>>
Mysql在Linux运行时新增配置文件提示:World-wrirable config file ‘/etc/mysql/conf.d/my.cnf‘ is ignored 权限过高导致
查看>>