Java creates SmartArt graphics in PPT

SmartArt graphics can express the logical relationship between content and viewpoint through different layout and combination of text and graphics, which can quickly and effectively convey the intention and information of designers. This visual representation of graphic expression is commonly used in PPT, Word, Excel and other office documents. This article takes the creation of SmartArt graphics in PPT as an example to introduce the specific methods realized through Java programs.
Tool: free flame.presentation for Java (free version)
Jar access and import: Official Website Download jar package And unzip the jar file under the lib folder into the Java program, or through the maven warehouse download and import.

When you create a SmartArt shape here, you can add content to the shape created by default, or you can customize the graphic node to add content.

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

public class SmartArt {
    public static void main(String[] args) throws Exception{
        //Create a PPT document and get a slide (the blank PPT document created contains one slide by default)
        Presentation ppt = new Presentation();
        ISlide slide = ppt.getSlides().get(0);

        //Create SmartArt graphic 1
        ISmartArt smartArt1 = slide.getShapes().appendSmartArt(50,50,200,200, SmartArtLayoutType.BASIC_CYCLE);//Add SmartArt graphics of the specified size and layout type at the specified location of the slide
        smartArt1.setColorStyle(SmartArtColorType.COLORFUL_ACCENT_COLORS_4_TO_5);//Set SmartArt graphic color type
        smartArt1.setStyle(SmartArtStyleType.INTENCE_EFFECT);//Set SmartArt graphic style
        ISmartArtNode smartArtNode1 = smartArt1.getNodes().get(0);
        smartArtNode1.getTextFrame().setText("Design");//Get default node, add content
        smartArt1.getNodes().get(1).getTextFrame().setText("imitate");
        smartArt1.getNodes().get(2).getTextFrame().setText("Study");
        smartArt1.getNodes().get(3).getTextFrame().setText("practice");
        smartArt1.getNodes().get(4).getTextFrame().setText("innovate");

        //Create SmartArt graphic 2, customize node content
        ISmartArt smartArt2 = slide.getShapes().appendSmartArt(400,200,200,200,SmartArtLayoutType.BASIC_RADIAL);
        smartArt2.setColorStyle(SmartArtColorType.DARK_2_OUTLINE);
        smartArt2.setStyle(SmartArtStyleType.MODERATE_EFFECT);
        //Delete default node (graphic in SmartArt)
        for (Object a : smartArt2.getNodes()) {
            smartArt2.getNodes().removeNode((ISmartArtNode) a);
        }
        //Add a parent node
        ISmartArtNode node2 = smartArt2.getNodes().addNode();
        //Add three child nodes under the parent node
        ISmartArtNode node2_1 = node2.getChildNodes().addNode();
        ISmartArtNode node2_2 = node2.getChildNodes().addNode();
        ISmartArtNode node2_3 = node2.getChildNodes().addNode();
        //Set text and text size on nodes
        node2.getTextFrame().setText("equipment");
        node2.getTextFrame().getTextRange().setFontHeight(14f);
        node2_1.getTextFrame().setText("Mechanics");
        node2_1.getTextFrame().getTextRange().setFontHeight(12f);
        node2_2.getTextFrame().setText("electrical");
        node2_2.getTextFrame().getTextRange().setFontHeight(12f);
        node2_3.getTextFrame().setText("automation");
        node2_3.getTextFrame().getTextRange().setFontHeight(12f);

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

Create results:

(end)

Tags: Java Excel Maven

Posted on Fri, 08 May 2020 08:09:42 -0700 by Arc