在 C# 中的 VDW 中創建流程圖樣式組織結構圖
使用服務器端 Aspose.Diagram for .NET API 在 VDW 文檔中創建本機和高性能的流程圖樣式組織結構圖,無需使用任何軟件,如 Microsoft 或 Open Office、Adobe PDF。
如何使用 C# 在 VDW 文件中創建流程圖樣式組織結構圖
為了在 VDW 文件中創建流程圖樣式的組織結構圖,我們將使用
API 是一個功能豐富、功能強大且易於使用的文檔操作和合併 API 平台 C#。打開
包管理器,搜索 Aspose.Diagram 並安裝。您也可以從包管理器控制台使用以下命令。
命令
PM> Install-Package Aspose.Diagram
在 C# 中的 VDW 文件中創建流程圖樣式組織圖的步驟
創建流程圖風格的組織結構圖
只需幾行代碼即可完成 API。
- 從模板創建 diagram。
- 通過其 id 選擇頁面
- 將組織節點形狀添加到頁面。
- 將連接器添加到頁面以連接形狀及其父級。
- 通過調用佈局方法自動佈局
- 調用 Save() 方法並將文件名(完整路徑)和格式(VSDX)作為參數傳遞。
- 現在您可以在 Microsoft Office、Adobe PDF 或任何其他兼容程序中打開和使用 VSDX 文件。
系統要求
所有主要平台和操作系統都支持我們的 API。在執行以下代碼之前,請確保您的系統具有以下先決條件。
- Microsoft Windows 或具有 .NET Framework、.NET Core、Mono 或 COM Interop 的兼容操作系統- Microsoft Visual Studio 等開發環境- Aspose.Diagram for .NET 在您的項目中引用的 DLL - 使用上面的下載按鈕從 NuGet 安裝
在 VDW 文件中創建流程圖樣式組織圖 - C#
// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir_FlowChart(); | |
// Load masters from any existing diagram, stencil or template | |
// And add in the new diagram | |
string visioStencil = dataDir + "Basic Shapes.vss"; | |
const string rectangleMaster = "Rectangle"; | |
const string connectorMaster = "Dynamic connector"; | |
const int pageNumber = 0; | |
const double width = 1; | |
const double height = 1; | |
double pinX = 4.25; | |
double pinY = 9.5; | |
// Define values to construct the hierarchy | |
List<string> listPos = new List<string>(new string[] { "0", "0:0", "0:1", "0:2", "0:3", "0:4", "0:5", "0:6", "0:0:0", "0:0:1", "0:3:0", "0:3:1", "0:3:2", "0:6:0", "0:6:1" }); | |
// Define a Hashtable to map the string name to long shape id | |
Hashtable shapeIdMap = new Hashtable(); | |
// Create a new diagram | |
Diagram diagram = new Diagram(visioStencil); | |
foreach (string orgnode in listPos) | |
{ | |
// Add a new rectangle shape | |
long rectangleId = diagram.AddShape(pinX++, pinY++, width, height, rectangleMaster, pageNumber); | |
// Set the new shape's properties | |
Shape shape = diagram.Pages[pageNumber].Shapes.GetShape(rectangleId); | |
shape.Text.Value.Add(new Txt(orgnode)); | |
shape.Name = orgnode; | |
shapeIdMap.Add(orgnode, rectangleId); | |
} | |
// Create connections between nodes | |
foreach (string orgName in listPos) | |
{ | |
int lastColon = orgName.LastIndexOf(':'); | |
if(lastColon > 0) | |
{ | |
string parendName = orgName.Substring(0, lastColon); | |
long shapeId = (long)shapeIdMap[orgName]; | |
long parentId = (long)shapeIdMap[parendName]; | |
Shape connector1 = new Shape(); | |
long connecter1Id = diagram.AddShape(connector1, connectorMaster, pageNumber); | |
diagram.Pages[pageNumber].ConnectShapesViaConnector(parentId, ConnectionPointPlace.Right, | |
shapeId, ConnectionPointPlace.Left, connecter1Id); | |
} | |
} | |
//auto layout FlowChart | |
LayoutOptions flowChartOptions = new LayoutOptions | |
{ | |
LayoutStyle = LayoutStyle.FlowChart, | |
Direction = LayoutDirection.TopToBottom, | |
EnlargePage = true | |
}; | |
diagram.Pages[pageNumber].Layout(flowChartOptions); | |
// Save diagram | |
diagram.Save(dataDir + "FlowChart_out.vsdx", SaveFileFormat.VSDX); |
關於Aspose.Diagram for .NET API
Aspose.Diagram 是 Microsoft Visio 文檔格式操作 API。您可以輕鬆加載、創建、修改、操作包括圖形元素在內的 Visio 圖表轉換為其他格式,例如 PDF、XPS、JPEG、PNG、BMP、TIFF、SVG、EMF 等。它是一個獨立的 API,不需要安裝 Microsoft Visio 或任何其他軟件。在線 VDW 流程圖樣式組織結構圖現場演示
立即訪問我們的 VDW 文檔中創建流程圖樣式組織結構圖 現場演示網站 .現場演示有以下好處
VDW 什麼是 VDW 文件格式
VDW 是 Visio 圖形服務文件格式,它指定呈現 Web 繪圖所需的流和存儲。 Web 繪圖是繪圖頁面、形狀、字體、圖像、數據連接和diagram更新信息的集合,可以呈現為矢量或光柵繪圖。 VDW 文件也可以在 Microsoft Visio 中打開,但主要保存在網絡上使用。 Microsoft Visio 能夠將 Visio 文件轉換為多種不同的文件格式,包括 PNG、BMP、PDF 等。
閱讀更多