通过 Java 管理 Microsoft® Visio 文件元数据
使用服务器端 Java API 查看、添加、更新、删除或提取内置和自定义 Visio 文件属性。
Java Visio API 支持标题、作者姓名、文档统计等系统定义(内置)属性以及名称-值对形式的用户定义(自定义)属性的管理。有 Diagram 类 加载文件,以及 页面集合 处理页面的集合以及 页面类 用于表示单个页面。与这些类、文档属性一起,customprops 使元数据管理的过程变得简单。
管理内置属性
为了管理系统定义的属性,API 提供 文档属性 , 程序员可以轻松访问内置属性并更新其值。
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(AutoFitShapesInVisio.class); | |
// load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "BFlowcht.vsdx"); | |
//// Display Visio version and document modification time at different stages | |
System.out.println(diagram.getVersion()); | |
System.out.println(diagram.getDocumentProps().getBuildNumberCreated()); | |
System.out.println(diagram.getDocumentProps().getBuildNumberEdited()); | |
System.out.println(diagram.getDocumentProps().getTimeCreated()); | |
System.out.println(diagram.getDocumentProps().getTimeEdited()); | |
System.out.println(diagram.getDocumentProps().getTimePrinted()); | |
System.out.println(diagram.getDocumentProps().getTimeSaved()); | |
System.out.println(diagram.getDocumentProps().getCustomProps().getCount()); |
管理自定义属性
为了管理用户定义的属性,API 提供 自定义道具 ,开发人员可以轻松访问已添加的属性以及添加新属性。为了添加自定义属性, [添加方法]( https://apireference.aspose.com/diagram/java/com.aspose.diagram/custompropcollection#add(com.aspose.diagram.CustomProp) 添加属性并返回新属性的引用作为 自定义道具 目的。 CustomProp 类用于检索文档属性的名称、值和类型,如 姓名 , 自定义值 , 财产类型 枚举值。
Java 在 Visio 文件中添加元数据的代码
// 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(AutoFitShapesInVisio.class); | |
// Load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
//// Get CustomProperties of diagram | |
CustomPropCollection customProperties = diagram.getDocumentProps().getCustomProps(); | |
//Set property of CustomProp | |
CustomProp customProp = new CustomProp(); | |
customProp.setPropType(PropType.STRING); | |
customProp.getCustomValue().setValueString ("Test"); | |
//Add CustomProp to Collection | |
customProperties.add(customProp); |
Java 删除 Visio 文件中的属性的代码
// 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(AutoFitShapesInVisio.class); | |
// Load a Visio diagram | |
Diagram diagram = new Diagram(dataDir + "Drawing1.vsdx"); | |
//// Get CustomProperties of diagram | |
CustomPropCollection customProperties = diagram.getDocumentProps().getCustomProps(); | |
//Remove CustomProp | |
for (int i = 0; i < customProperties.getCount(); i++) | |
{ | |
CustomProp customProp = customProperties.get(i); | |
if (customProp.getName()== "Test") | |
{ | |
customProperties.remove(customProp); | |
} | |
} |