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

你可能感兴趣的文章
node-static 任意文件读取漏洞复现(CVE-2023-26111)
查看>>
Node.js 8 中的 util.promisify的详解
查看>>
node.js debug在webstrom工具
查看>>
Node.js Event emitter 详解( 示例代码 )
查看>>
Node.js GET、POST 请求是怎样的?
查看>>
Node.js HTTP模块详解:创建服务器、响应请求与客户端请求
查看>>
Node.js RESTful API如何使用?
查看>>
node.js url模块
查看>>
Node.js Web 模块的各种用法和常见场景
查看>>
Node.js 之 log4js 完全讲解
查看>>
Node.js 函数是什么样的?
查看>>
Node.js 函数计算如何突破启动瓶颈,优化启动速度
查看>>
Node.js 切近实战(七) 之Excel在线(文件&文件组)
查看>>