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

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

在Java程序中编辑PPT幻灯片中的SmartArt图形,涉及多个操作步骤。以下内容将详细介绍如何进行这些操作,包括样式重置、颜色设置、节点添加/删除、内容编辑以及超链接添加等。

工具说明

推荐使用 Free Spire.Presentation for Java 免费版本进行操作。该工具通过jar包形式导入至Java程序中,可以通过以下两种方式进行配置:

  • 方法一:通过官方网站下载

    • 访问官方网站并解压Spire.Presentation.jar文件。
    • 将lib文件夹中的Spire.Presentation.jar添加至Java开发环境的依赖库中。
  • 方法二:在Maven项目中配置

    • 在项目的pom.xml文件中添加以下依赖配置:
      e-iceblue
      http://repo.e-iceblue.cn/repository/maven-public/
      e-iceblue
      spire.presentation.free
      3.9.0
    • 完成后,通过Maven导入相应的jar包。
  • Java示例

    以下是一个修改SmartArt图形的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);                // 获取并修改节点内容        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();    }}

    测试结果

    修改后的PPT幻灯片在播放时会显示添加的超链接效果。新节点的内容和样式修改也将生效。

    注意事项

    • 添加超链接时,确保目标地址有效。
    • 如果需要删除节点,请根据实际需求调整代码。
    • 保存时请注意文件格式选择。

    通过以上步骤,您可以在Java程序中方便地编辑PPT幻灯片中的SmartArt图形。

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

    你可能感兴趣的文章
    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 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 toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android
    查看>>
    NO.23 ZenTaoPHP目录结构
    查看>>
    no1
    查看>>
    NO32 网络层次及OSI7层模型--TCP三次握手四次断开--子网划分
    查看>>
    NOAA(美国海洋和大气管理局)气象数据获取与POI点数据获取
    查看>>
    NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata
    查看>>
    node exporter完整版
    查看>>