0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

C# パワーポイントでスマートアートを挿入

0
Last updated at Posted at 2021-06-30

「SmartArt」(スマートアート)とは、組織図やフロートチャートなどの図表を簡単に作成できる機能です。メント)とは、XMLをベースとしたオフィススイート用のファイルフォーマットです。今日はSpire.Presentationという無料のライブラリを使って、パワーポイントでスマートアートを挿入する方法を紹介します。

 下準備

1.E-iceblueの公式サイトからFree Spire. Presentation無料版をダウンロードしてください。

 

f:id:lendoris:20210630145016p:plain

2.Visual Studioを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire. Presentation.dllを参照に追加してください。

(Net 4.0を例としたら、デフォルトパスは“Bin→NET4.0→Presentation.dll”というようになります。)

f:id:lendoris:20210630145022p:plain

```C# using Spire.Presentation; namespace RemoveWatermark {
class Program
{

    static void Main(string[] args)
    {
        //スマートアートを挿入します。
        Presentation pres = new Presentation();
        Spire.Presentation.Diagrams.ISmartArt sa = pres.Slides[0].Shapes.AppendSmartArt(20, 40, 300, 300, Spire.Presentation.Diagrams.SmartArtLayoutType.Gear);

        //スマートアートのタイプを設定します。
        sa.Style = Spire.Presentation.Diagrams.SmartArtStyleType.SubtleEffect;
        sa.ColorStyle = Spire.Presentation.Diagrams.SmartArtColorType.GradientLoopAccent3;

        //図形をすべて除きます。
        foreach (object a in sa.Nodes)
            sa.Nodes.RemoveNode(a);

        //カスタムの図形を追加します。
        Spire.Presentation.Diagrams.ISmartArtNode node = sa.Nodes.AddNode();
        sa.Nodes[0].TextFrame.Text = "aa";
        node = sa.Nodes.AddNode();
        node.TextFrame.Text = "bb";
        node.TextFrame.TextRange.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Solid;
        node.TextFrame.TextRange.Fill.SolidColor.KnownColor = KnownColors.Black;

        //保存します。
        pres.SaveToFile("SmartArtTest1.pptx", FileFormat.Pptx2007);
        System.Diagnostics.Process.Start("SmartArtTest1.pptx");


    }
}

}

<h4><strong>実行結果</strong></h4>
<p><img src="https://cdn-ak.f.st-hatena.com/images/fotolife/l/lendoris/20210630/20210630145120.png" alt="f:id:lendoris:20210630145120p:plain" width="554" height="320" loading="lazy" title="" class="hatena-fotolife" itemprop="image" /></p>
<p> </p>
0
0
4

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?