이 문서에서는 C#에서 Visio 다이어그램을 만드는 방법에 대해 설명합니다. 단계별 프로세스와 C#에서 Visio 다이어그램을 자동화하는 작동 샘플 코드를 공유합니다. 또한 출력 Visio 다이어그램을 다른 파일 형식으로 내보내는 방법도 다룹니다.
C#에서 Visio 다이어그램을 만드는 단계
- Visio 다이어그램을 만들려면 Aspose.Diagram API를 설치하세요.
- Diagram 클래스의 인스턴스를 생성합니다.
- 스텐실 파일을 사용하여 마스터 추가
- AddShape() 메서드를 사용하여 사각형 모양을 삽입하고 다양한 속성을 설정합니다.
- Save() 메서드를 사용하여 출력 Visio 다이어그램을 내보냅니다.
이 단계는 C#에서 Visio를 만드는 방법에 대한 개요를 제공합니다. 먼저, 처음부터 다이어그램을 만들고 마스터 스텐실을 로드합니다. 치수, 위치, 페이지 번호와 같은 다양한 매개변수를 지정하면서 모양을 삽입합니다. 마지막으로 출력 Visio 다이어그램을 VSDX 파일로 렌더링하여 프로세스를 완료합니다.
C#에서 Visio 다이어그램을 프로그래밍 방식으로 만드는 코드
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
이 코드 조각을 사용하여 C#에서 Visio의 프로세스 다이어그램을 그릴 수 있습니다. 이 샘플 코드는 기본 버전이지만 요구 사항에 맞게 여러 다른 유형의 모양과 커넥터를 그리도록 향상시킬 수 있습니다. 마찬가지로 출력 파일 형식을 조정하여 생성된 도면을 요구 사항에 따라 래스터 이미지, 벡터 이미지, PDF 또는 기타 형식으로 렌더링합니다.
이 튜토리얼에서는 C#에서 Visio 다이어그램을 프로그래밍 방식으로 만드는 방법에 대한 정보를 다루었습니다. 그러나 VSD 파일 변환을 알아보고 싶다면 C#에서 VSD를 VSDX로 변환의 기사를 읽어보세요.