グループシェイプを追加

このチュートリアルでは、Aspose.Words for .NET を使用して、複数の図形を含むグループ図形を Word 文書に追加する方法について説明します。グループ図形を使用すると、複数の図形を 1 つのエンティティとして結合して操作できます。

前提条件

このチュートリアルを実行するには、次のものが必要です。

  • Aspose.Words for .NET ライブラリがインストールされています。
  • C# と Word 文書を使用した Words Processing に関する基本的な知識。

ステップ1: ドキュメントディレクトリを設定する

まず、ドキュメントディレクトリへのパスを設定します。"YOUR DOCUMENT DIRECTORY"ドキュメントを保存するディレクトリへの実際のパスを入力します。

string dataDir = "YOUR DOCUMENT DIRECTORY";

ステップ2: 新しいドキュメントとGroupShapeを作成する

新しいインスタンスを作成するDocumentクラスとGroupShapeドキュメントを操作するオブジェクト。

Document doc = new Document();
doc.EnsureMinimum();
GroupShape groupShape = new GroupShape(doc);

ステップ 3: GroupShape に図形を作成して追加する

次のような個別の図形を作成します。accentBorderShapeそしてactionButtonShape使用してShapeクラス。必要に応じてプロパティをカスタマイズします。これらの図形をgroupShape物体。

Shape accentBorderShape = new Shape(doc, ShapeType.AccentBorderCallout1) { Width = 100, Height = 100 };
groupShape.AppendChild(accentBorderShape);

Shape actionButtonShape = new Shape(doc, ShapeType.ActionButtonBeginning)
{
    Left = 100,
    Width = 100,
    Height = 200
};
groupShape.AppendChild(actionButtonShape);

ステップ4: GroupShapeの寸法を設定する

幅、高さ、座標サイズを設定します。groupShape.

groupShape.Width = 200;
groupShape.Height = 200;
groupShape.CoordSize = new Size(200, 200);

ステップ5: GroupShapeをドキュメントに挿入する

作成するDocumentBuilderオブジェクトを挿入し、groupShape文書にInsertNode方法。

DocumentBuilder builder = new DocumentBuilder(doc);
builder.InsertNode(groupShape);

ステップ6: ドキュメントを保存する

指定されたディレクトリにドキュメントを保存するには、Saveメソッド。適切なファイル拡張子を持つファイル名を指定します。この例では、ドキュメントを「WorkingWithShapes.AddGroupShape.docx」として保存します。

doc.Save(dataDir + "WorkingWithShapes.AddGroupShape.docx");

Aspose.Words for .NET を使用してグループ図形を追加するためのサンプル ソース コード

	//ドキュメントディレクトリへのパス
	string dataDir = "YOUR DOCUMENT DIRECTORY";

	Document doc = new Document();
	doc.EnsureMinimum();
	GroupShape groupShape = new GroupShape(doc);
	Shape accentBorderShape = new Shape(doc, ShapeType.AccentBorderCallout1) { Width = 100, Height = 100 };
	groupShape.AppendChild(accentBorderShape);
	Shape actionButtonShape = new Shape(doc, ShapeType.ActionButtonBeginning)
	{
		Left = 100, Width = 100, Height = 200
	};
	groupShape.AppendChild(actionButtonShape);
	groupShape.Width = 200;
	groupShape.Height = 200;
	groupShape.CoordSize = new Size(200, 200);
	DocumentBuilder builder = new DocumentBuilder(doc);
	builder.InsertNode(groupShape);
	doc.Save(dataDir + "WorkingWithShapes.AddGroupShape.docx");

これで完了です。Aspose.W を使用して、複数の図形を含むグループ図形を Word 文書に追加できました。