バージョン6.0以来、Spire.Docは様々な形状(線、長方形、基本形状、矢印、フローチャート、数式形状、星と旗、注釈)の追加をサポートしています。 形状の組み合わせのセット。 この記事では、Spire.Docを使用してWordにシェイプとシェイプの組み合わせを追加する方法について説明します。
使用する必要のあるツール:Spire.Doc for .NET
単一のシェイプを追加する
【C#】
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Insert_Shapes1
{
class Program
{
static void Main(string[] args)
{
//ドキュメントインスタンスを作成する
Document doc = new Document();
//セクションを追加
Section sec = doc.AddSection();
//段落を追加する
Paragraph para1 = sec.AddParagraph();
//ハート型を挿入する
ShapeObject shape1 = para1.AppendShape(50, 50, ShapeType.Heart);
shape1.FillColor = Color.Red;
shape1.StrokeColor = Color.Red;
shape1.HorizontalPosition = 200;
shape1.VerticalPosition = 20;
//矢印を挿入する
ShapeObject shape2 = para1.AppendShape(100, 100, ShapeType.Arrow);
shape2.FillColor = Color.Green;
shape2.StrokeColor = Color.Black;
shape2.LineStyle = ShapeLineStyle.Double;
shape2.StrokeWeight = 3;
shape2.HorizontalPosition = 200;
shape2.VerticalPosition = 100;
//数式シンボルを挿入する+
ShapeObject shape3 = para1.AppendShape(50, 50, ShapeType.Plus);
shape3.FillColor = Color.Red;
shape3.StrokeColor = Color.Red;
shape3.LineStyle = ShapeLineStyle.Single;
shape3.StrokeWeight = 3;
shape3.HorizontalPosition = 200;
shape3.VerticalPosition = 200;
//星を挿入する
ShapeObject shape4 = para1.AppendShape(50, 50, ShapeType.Star);
shape4.FillColor = Color.Gold;
shape4.StrokeColor = Color.Gold;
shape4.LineStyle = ShapeLineStyle.Single;
shape4.HorizontalPosition = 200;
shape4.VerticalPosition = 300;
//ドキュメントを保存
doc.SaveToFile("図形を挿入.docx", FileFormat.Docx2010);
}
}
}
コードをデバッグして実行した後、生成されたドキュメントは以下のようになります:
グラフィックの組み合わせを挿入
【C#】
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using System.Drawing;
namespace Insert_ShapeGroups
{
class Program
{
static void Main(string[] args)
{
//ドキュメントインスタンスを作成し、セクションと段落を追加する
Document doc = new Document();
Section sec = doc.AddSection();
Paragraph para = sec.AddParagraph();
//形状の組み合わせを作成してサイズを設定する
ShapeGroup shapegr = para.AppendShapeGroup(200, 400);
//シェイプの組み合わせに四角形を追加する
shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.Rectangle)
{
Width = 500,
Height = 300,
LineStyle = ShapeLineStyle.ThickThin,
StrokeColor = System.Drawing.Color.Blue,
StrokeWeight = 1.5,
});
//形状の組み合わせに三角形を追加する
shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.RightTriangle)
{
Width = 500,
Height = 300,
VerticalPosition = 301,
LineStyle = ShapeLineStyle.ThickThin,
StrokeColor = System.Drawing.Color.Green,
StrokeWeight = 1.5,
});
//図形の組み合わせに十字の矢印を追加する
shapegr.ChildObjects.Add(new ShapeObject(doc, ShapeType.QuadArrow)
{
Width = 500,
Height = 300,
VerticalPosition = 601,
LineStyle = ShapeLineStyle.ThickThin,
StrokeColor = System.Drawing.Color.Blue,
StrokeWeight = 1.5,
});
//ドキュメントを保存
doc.SaveToFile("グラフィックの組み合わせを挿入.docx", FileFormat.Docx2010);
}
}
}