C# で Visio 図を作成する

この記事では、C# で Visio ダイアグラムを作成する 方法について説明します。C# で Visio ダイアグラムの作成を自動化する ための段階的なプロセスと実用的なサンプル コードを紹介します。さらに、出力 Visio ダイアグラムをさまざまなファイル形式でエクスポートする方法についても説明します。

C# で Visio 図を作成する手順

  1. Visio ダイアグラムを作成するには Aspose.Diagram API をインストールしてください
  2. Diagram クラスのインスタンスを作成する
  3. ステンシルファイルを使用してマスターを追加する
  4. AddShape()メソッドを使用して長方形を挿入し、さまざまなプロパティを設定します
  5. Save() メソッドを使用して出力 Visio ダイアグラムをエクスポートします。

これらの手順では、C# で Visio を作成する方法の概要を示します。まず、最初から図を作成し、マスター ステンシルを読み込みます。寸法、位置、ページ番号などのさまざまなパラメータを指定しながら図形を挿入します。最後に、出力 Visio 図を VSDX ファイルとしてレンダリングして、プロセスを完了します。

C# でプログラム的に Visio 図を作成するコード

using Aspose.Diagram;
class CreateVisioDiagram
{
static void Main()
{
new License().SetLicense("license.lic");// Initialize the Drawing License
// Create a new instance of a diagram
Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram();
// Define the name of the master (template) to be used for creating shapes
string masterName = "Rectangle";
diagram.AddMaster("Basic Shapes.vss", masterName);
// Define the dimensions and position for the new shape
double width = 2, height = 2, pinX = 4.25, pinY = 4.5;
// Add a new rectangle shape to the diagram using the specified master
long rectangleId = diagram.AddShape(pinX, pinY, width, height, masterName, 0);
// Retrieve the shape by its ID for modification
Aspose.Diagram.Shape rectangle = diagram.Pages[0].Shapes.GetShape(rectangleId);
// Set the position of the shape by modifying its PinX and PinY properties
rectangle.XForm.PinX.Value = 5;
rectangle.XForm.PinY.Value = 5;
// Set the type of the shape to indicate it is a standard shape
rectangle.Type = Aspose.Diagram.TypeValue.Shape;
// Add text to the shape
rectangle.Text.Value.Add(new Aspose.Diagram.Txt("Aspose Diagram"));
// Apply a predefined text style to the shape's text
rectangle.TextStyle = diagram.StyleSheets[3];
// Save the modified diagram to a file
diagram.Save("Visio_out.vsdx", Aspose.Diagram.SaveFileFormat.Vsdx);
}
}

このコード スニペットを使用すると、Visio のプロセス図を C# で描画できます。このサンプル コードは基本バージョンですが、これを拡張して、要件に合わせて他の種類の図形やコネクタを描画することもできます。同様に、出力ファイル形式を調整して、生成された図面を要件に基づいてラスター イメージ、ベクター イメージ、PDF、またはその他の形式でレンダリングします。

このチュートリアルでは、C# でプログラム的に Visio 図を作成する 方法について説明しました。ただし、VSD ファイルの変換について詳しく知りたい場合は、C# で VSD を VSDX に変換する の記事をお読みください。

 日本語