保护取消保护 Visio 形状

Visio 文件包含各种类型的形状和连接器以创建不同的图表。在某些情况下,您可能希望保护特定形状免受更改。在这种情况下,本文介绍了如何在 C# 中以编程方式保护或取消保护 Visio 图表中的形状。

保护或取消保护 Visio 形状文件 - .NET API 安装

Aspose.Diagram for .NET API 支持创建或编辑不同类型的图表,如流程图、组织结构图等。您可以使用各种文件格式,无需安装 Microsoft Visio 应用程序.您可以通过从 Downloads 部分下载参考 DLL 文件或运行以下 NuGet 安装命令轻松安装 API:

PM> Install-Package Aspose.Diagram

保护 Visio 形状免受 C# 中的更改

您可以设置不同的属性来保护 Visio 图表中的形状免受更改。例如,您可以锁定文本编辑、旋转、高度等。请按照以下步骤保护 VSD 或 VSDX Visio 图表文件中的形状:

  1. 使用 Diagram 类加载源 Visio 图表。
  2. 访问页面,然后使用其 ID 访问特定形状。
  3. 保护不同的形状属性免受更改。
  4. 保存输出图。

下面的代码片段演示了如何在 C# 中以编程方式保护 Visio 形状:

// 负载输入图
Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram("ProtectAndUnprotect.vsd");

// 按名称获取页面
Aspose.Diagram.Page page = diagram.Pages.GetPage("Flow 1");

// 通过 ID 获取形状
Aspose.Diagram.Shape shape = page.Shapes.GetShape(1);

// 设置保护
shape.Protection.LockAspect.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockCrop.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockCustProp.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockDelete.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockHeight.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockMoveX.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockMoveY.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockRotate.Value = Aspose.Diagram.BOOL.True;
shape.Protection.LockTextEdit.Value = Aspose.Diagram.BOOL.True;

// 保存受保护的输出 visio 图
diagram.Save("VisioShapeProtection_Out.vdx", Aspose.Diagram.SaveFileFormat.VDX);

在 C# 中取消保护 Visio 形状

您可以按照以下步骤取消保护 Visio 图表中的形状:

  1. 加载输入的 Visio 图表文件。
  2. 通过访问特定页面及其形状来取消对形状的保护。
  3. 导出输出 Visio 文件。

以下代码示例显示如何在 C# 中以编程方式取消保护 Visio 图表中的形状:

// 负载输入图
Aspose.Diagram.Diagram diagram = new Aspose.Diagram.Diagram(dataDir + "ProtectAndUnprotect.vsd");

// 按名称获取页面
Aspose.Diagram.Page page = diagram.Pages.GetPage("Flow 1");

// 通过 ID 获取形状
Aspose.Diagram.Shape shape = page.Shapes.GetShape(1);

// 取消保护 Visio 形状
shape.Protection.LockAspect.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockCrop.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockCustProp.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockDelete.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockHeight.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockMoveX.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockMoveY.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockRotate.Value = Aspose.Diagram.BOOL.False;
shape.Protection.LockTextEdit.Value = Aspose.Diagram.BOOL.False;

// 保存未受保护的输出 visio 图
diagram.Save("VisioShape_unProtect_Out.vdx", Aspose.Diagram.SaveFileFormat.VDX);

结论

在本文中,您学习了如何在 C# 中以编程方式保护或取消保护 VSD 或 VSDX 格式的 Visio 图表文件中的形状。此外,您可以查看 documentation 空间以了解 API 的各种其他功能。如果您有任何问题,请随时通过 论坛 与我们联系。

也可以看看