使用保护

设置保护 Visio Diagram

保护图表允许用户锁定背景、母版(模板)、形状和样式,使它们无法被编辑。这对于保护公司风格很有用,例如,并确保一组图表的外观一致。开发人员可以使用Aspose.Diagram for Java.

编辑保护Visio Diagram

getProtectBkgnds、getProtectMasters、getProtectShapes 和 getProtectStyles 方法,由文档设置类支持 com.aspose.diagram.BoolValue 对象。这些属性可用于保护和取消保护 Microsoft Visio 图。

在 Microsoft Visio 中,您以这种方式保护文档:

  1. 在Microsoft Visio开一个diagram。
  2. 打开绘图资源管理器窗口。
  3. 右键单击 diagram 并选择保护文档从菜单中。
  4. 在“保护文档”窗口中,选中或清除选项以锁定或解锁不同的 diagram 元素。
  5. 点击好的.

请查看我们如何手动检查或清除选项。

待办事项:图片_替代_文本

在 Java 应用程序中使用以下代码执行相同的任务 – 锁定和解锁 diagram 的不同元素 – 使用 Aspose.Diagram for Java。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(VisioDiagramProtection.class);
//Load diagram
Diagram diagram = new Diagram(dataDir + "ProtectAndUnprotect.vsd");
diagram.getDocumentSettings().setProtectBkgnds(BOOL.TRUE);
diagram.getDocumentSettings().setProtectMasters(BOOL.TRUE);
diagram.getDocumentSettings().setProtectShapes(BOOL.TRUE);
diagram.getDocumentSettings().setProtectStyles(BOOL.TRUE);
// save diagram
diagram.save(dataDir + "VisioDiagramProtection_Out.vdx", SaveFileFormat.VDX);

编辑Visio形状保护

保护 Visio 形状允许用户锁定形状的特定方面。可以通过形状保护锁定的形状方面包括宽度、高度、x 位置、y 位置、旋转等。开发人员可以使用Aspose.Diagram for Java.

getLockAspect(), 获取锁定开始(), getLockCalcWH(), getLockCrop(), getLockCustProp(), 获取锁定删除(), getLockEnd(), 获取锁定格式(), getLockFromGroupFormat(), getLockGroup(), 获取锁定高度(), getLockMoveX(), getLockMoveY(), getLockRotate() 方法, 获取锁定选择(), 获取锁定文本编辑(), getLockThemeColors(), getLockThemeEffects() 方法, **getLockVtxEdit()获取锁定宽度()**公开的方法保护类支持 com.aspose.diagram.BoolValue 对象。这些方法可用于保护/取消保护形状。

在 Visio 中,您需要执行以下操作来保护任何形状:

  1. 在Microsoft Visio开一个diagram。
  2. 选择一个形状。
  3. 选择保护来自格式菜单 (Visio 2007),或选择保护来自开发商菜单(Visio 2010)。
  4. 在里面保护窗口,选择或清除选项以锁定或解锁形状属性。
  5. 点击好的.

形状的保护选项,如 Microsoft Visio 所示

待办事项:图片_替代_文本

在您的 Java 应用程序中使用以下代码来使用 Aspose.Diagram for Java 执行相同的操作(锁定/解锁任何形状属性)。

// For complete examples and data files, please go to https://github.com/aspose-diagram/Aspose.Diagram-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(VisioShapeProtection.class);
//Load diagram
Diagram diagram = new Diagram(dataDir + "ProtectAndUnprotect.vsd");
// get page by name
Page page = diagram.getPages().getPage("Flow 1");
// get shape by ID
Shape shape = page.getShapes().getShape(1);
// set protections
shape.getProtection().getLockAspect().setValue(BOOL.TRUE);
shape.getProtection().getLockBegin().setValue(BOOL.TRUE);
shape.getProtection().getLockCalcWH().setValue(BOOL.TRUE);
shape.getProtection().getLockCrop().setValue(BOOL.TRUE);
shape.getProtection().getLockCustProp().setValue(BOOL.TRUE);
shape.getProtection().getLockDelete().setValue(BOOL.TRUE);
shape.getProtection().getLockEnd().setValue(BOOL.TRUE);
shape.getProtection().getLockFormat().setValue(BOOL.TRUE);
shape.getProtection().getLockFromGroupFormat().setValue(BOOL.TRUE);
shape.getProtection().getLockGroup().setValue(BOOL.TRUE);
shape.getProtection().getLockHeight().setValue(BOOL.TRUE);
shape.getProtection().getLockMoveX().setValue(BOOL.TRUE);
shape.getProtection().getLockMoveY().setValue(BOOL.TRUE);
shape.getProtection().getLockRotate().setValue(BOOL.TRUE);
shape.getProtection().getLockSelect().setValue(BOOL.TRUE);
shape.getProtection().getLockTextEdit().setValue(BOOL.TRUE);
shape.getProtection().getLockThemeColors().setValue(BOOL.TRUE);
shape.getProtection().getLockThemeEffects().setValue(BOOL.TRUE);
shape.getProtection().getLockVtxEdit().setValue(BOOL.TRUE);
shape.getProtection().getLockWidth().setValue(BOOL.TRUE);
// save diagram
diagram.save(dataDir + "VisioShapeProtection_Out.vdx", SaveFileFormat.VDX);