「SmartArt」(スマートアート)とは、組織図やフロートチャートなどの図表を簡単に作成できる機能です。メント)とは、XMLをベースとしたオフィススイート用のファイルフォーマットです。今日はSpire.Presentationという無料のライブラリを使って、パワーポイントでスマートアートを挿入する方法を紹介します。
下準備
1.E-iceblueの公式サイトからFree Spire. Presentation無料版をダウンロードしてください。
2.Visual Studioを起動して新規プロジェクトを作成してから、インストールされたファイルにあった相応しいSpire. Presentation.dllを参照に追加してください。
(Net 4.0を例としたら、デフォルトパスは“Bin→NET4.0→Presentation.dll”というようになります。)
```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>

