在 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 等。
阅读更多