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

你可能感兴趣的文章
No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
查看>>
no connection could be made because the target machine actively refused it.问题解决
查看>>
No Datastore Session bound to thread, and configuration does not allow creation of non-transactional
查看>>
No fallbackFactory instance of type class com.ruoyi---SpringCloud Alibaba_若依微服务框架改造---工作笔记005
查看>>
No Feign Client for loadBalancing defined. Did you forget to include spring-cloud-starter-loadbalanc
查看>>
No mapping found for HTTP request with URI [/...] in DispatcherServlet with name ...的解决方法
查看>>
No mapping found for HTTP request with URI [/logout.do] in DispatcherServlet with name 'springmvc'
查看>>
No module named 'crispy_forms'等使用pycharm开发
查看>>
No module named 'pandads'
查看>>
No module named cv2
查看>>
No module named tensorboard.main在安装tensorboardX的时候遇到的问题
查看>>
No module named ‘MySQLdb‘错误解决No module named ‘MySQLdb‘错误解决
查看>>
No new migrations found. Your system is up-to-date.
查看>>
No qualifying bean of type XXX found for dependency XXX.
查看>>
No qualifying bean of type ‘com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>‘ available
查看>>
No resource identifier found for attribute 'srcCompat' in package的解决办法
查看>>
no session found for current thread
查看>>
No static resource favicon.ico.
查看>>
no such file or directory AndroidManifest.xml
查看>>
No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
查看>>