Edit ppt SmartArt graphics with Java

Time:2021-6-5

This paper introduces how to edit the existing SmartArt graphics in PPT slide in Java program, including resetting graphics style, color, adding / deleting graphics node, editing node content, adding hyperlink to node (link to web page, link to specified slide), etc. In PPT to create SmartArt graphics, read SmartArt graphics can refer to this articlearticleIt’s the way of life.

Tool: free spire.presentation for Java Free version, jar import, refer to the following methods:

Method 1Official websiteDownload jar package, unzip and import the spire.presentation.jar file in the Lib folder into the Java program;

Method 2To import in Maven program, you need to configure pom.xml file first, as follows:

com.e-iceblue
            http://repo.e-iceblue.cn/repository/maven-public/
        


  e-iceblue
  spire.presentation.free
  3.9.0

After configuration, import jar.

 

JavaExamples

import com.spire.presentation.*;
import com.spire.presentation.diagrams.*;

public class ModifySmartArt {
    public static void main(String[] args) throws Exception {
        //Loading PPT document
        Presentation ppt = new Presentation();
        ppt.loadFromFile("sample.pptx");

        //Get SmartArt graphics
        ISmartArt smartart = (ISmartArt) ppt.getSlides().get(0).getShapes().get(0);

        //Reset graphic style and color
        smartart.setStyle(SmartArtStyleType.SUBTLE_EFFECT);
        smartart.setColorStyle(SmartArtColorType.COLORFUL_ACCENT_COLORS_2_TO_3);

        //Get SmartArt graphics的节点集合
        ISmartArtNodeCollection nodes = smartart.getNodes();
        Nodes. Get (1). Gettextframe(). Settext ("new modified node content")// Change node content

        nodes.get(1).getTextFrame().setAutofitType(TextAutofitType.SHAPE);// Sets the text adaptation type of the node shape

        //Add hyperlink to node
        nodes.get(2).setClick(new ClickHyperlink(" https://www.baidu.com/ "));// Add hyperlinks to web pages
        nodes.get(3).setClick(new ClickHyperlink(ppt.getSlides().get(1)));// Adds a hyperlink to the specified slide

        //Add node
        ISmartArtNode newnode = nodes.get(5).getChildNodes().addNode();
        Newnode. Gettextframe(). Settext ("newly added node content");

        //nodes[0].ChildNodes[3].ChildNodes.RemoveNodeByPosition(0);// Delete node


        //Save document
        ppt.saveToFile("output.pptx", FileFormat.PPTX_2013);
        ppt.dispose();
    }
}

Test documentation:

The editing results are as follows. The added hyperlink effect needs to be viewed in the slide show:

 

(end of this article)

 

Recommended Today

[rust] basic data type

This article introduces the built-in data types provided by rust. Boolean type Boolean typeLogical values representing yes and No. It has two values:trueandfalseGenerally used in logical expressions, and, or, and not operations can be performed: fn main() { let x = true; let y: bool = ! x; // False, inverse operation let z = […]