博客
关于我
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/

你可能感兴趣的文章
Nginx学习总结(2)——Nginx手机版和PC电脑版网站配置
查看>>
Nginx学习总结(3)——Nginx配置及应用场景之高级配置
查看>>
Nginx学习总结(4)——负载均衡session会话保持方法
查看>>
Nginx学习总结(5)——Nginx基本配置备忘
查看>>
Nginx学习总结(6)——Nginx + https + 免费SSL证书配置指南
查看>>
Nginx学习总结(7)——Nginx配置HTTPS 服务器
查看>>
Nginx学习总结(8)——Nginx服务器详解
查看>>
Nginx学习总结(9)——前端跨域问题解决
查看>>
nginx学习笔记
查看>>
nginx学习笔记001---Nginx的启动、停止与重启
查看>>
nginx学习笔记002---Nginx代理配置_案例1_实现了对前端代码的方向代理_并且配置了后端api接口的访问地址
查看>>
nginx学习笔记003---Nginx代理配置_注意,在Windows中路径要用/
查看>>
Nginx学习笔记(一) Nginx架构
查看>>
nginx学习路线
查看>>
Nginx安装
查看>>
Nginx安装SSL模块 nginx: the “ssl” parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx
查看>>
nginx安装stream模块配置tcp/udp端口转发
查看>>
nginx安装Stream模块配置tcp/udp端口转发
查看>>
Nginx安装与常见命令
查看>>
nginx安装与配置
查看>>