LoginSignup
0
0

More than 3 years have passed since last update.

JavaはSmartArt図形をPowerPointに追加

Last updated at Posted at 2020-05-13

SmartArtグラフィックは、テキスト情報の視覚的表現であり、強力な組版機能を備えています。この記事では、Javaコードを使用してスライドにSmartArtグラフィックを作成し、そのレイアウトをカスタマイズする方法を示します。

使用ツール: Free Spire.Presentation for Java(無料版)

インストール方法1: Free Spire.Presentation for Javaパッケージをダウンロードして解凍します、次に、libフォルダーから、Spire.Presentation.jarパッケージをJavaアプリケーションにインポートします。

インストール方法2: Mavenウェアハウスを介してインストールおよびインポートします。詳細な操作手順については、リンクを参照してください:
https://www.e-iceblue.cn/licensing/install-spirepdf-for-java-from-maven-repository.html

Javaコード例

import com.spire.presentation.FileFormat;
import com.spire.presentation.ISlide;
import com.spire.presentation.Presentation;
import com.spire.presentation.diagrams.*;

public class AddSmartArt {

    public static void main(String[] args) throws Exception {

        //PowerPointドキュメントを作成する
        Presentation presentation = new Presentation();

        //最初のスライドを取得
        ISlide slide = presentation.getSlides().get(0);

        //スライドに組織図「'Organization Chart'」を作成する
        ISmartArt smartArt = slide.getShapes().appendSmartArt(60, 60, 500, 300, SmartArtLayoutType.ORGANIZATION_CHART);

        //SmartArtのスタイルと色を設定する
        smartArt.setStyle(SmartArtStyleType.MODERATE_EFFECT);
        smartArt.setColorStyle(SmartArtColorType.DARK_2_OUTLINE);

        //既定のノードを削除する(SmartArtのグラフィック)
        for (Object a : smartArt.getNodes()) {
            smartArt.getNodes().removeNode(0);
        }

        //親ノードを追加する
        ISmartArtNode node1 = smartArt.getNodes().addNode();

        //親ノードの下に4つの子ノードを追加する
        ISmartArtNode node1_1 = node1.getChildNodes().addNode();
        ISmartArtNode node1_2 = node1.getChildNodes().addNode();
        ISmartArtNode node1_3 = node1.getChildNodes().addNode();
        ISmartArtNode node1_4 = node1.getChildNodes().addNode();

        //ノードのテキストとテキストサイズを設定する
        node1.getTextFrame().setText("本社");
        node1.getTextFrame().getTextRange().setFontHeight(14f);
        node1_1.getTextFrame().setText("投資管理部");
        node1_1.getTextFrame().getTextRange().setFontHeight(12f);
        node1_2.getTextFrame().setText("財務部");
        node1_2.getTextFrame().getTextRange().setFontHeight(12f);
        node1_3.getTextFrame().setText("営業部");
        node1_3.getTextFrame().getTextRange().setFontHeight(12f);
        node1_4.getTextFrame().setText("技術部");
        node1_4.getTextFrame().getTextRange().setFontHeight(12f);

        //ドキュメントを保存します
        presentation.saveToFile("SmartArt.pptx", FileFormat.PPTX_2010);
        presentation.dispose();
    }
}

SmartArt効果を追加する:
smartart.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0