<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-diagram</artifactId>
<version>25.7</version>
</dependency>
如何在 Java 中读取 Visio 形状数据
按照以下步骤从 Visio 文件读取形状数据:
- 使用该类加载文件Diagram。
- 从图表中获取一页。
- 循环遍历页面上的形状。
- 打印形状 ID 和名称。
下面是一个 Java 代码片段,演示了如何在 Java 中读取 Visio 形状数据:
// Load the Visio file
Diagram diagram = new Diagram("Drawing1.vsdx");
// get pages count
System.out.println("Total Pages:" + diagram.getPages().getCount());
// Access the first page
Page page = diagram.getPages().get(0);
// Iterate through shapes
for (Shape shape : (Iterable<Shape>) page.getShapes()) {
System.out.println("Shape ID: " + shape.getID());
System.out.println("Name: " + shape.getName());
}
Total Pages: 1
Shape ID: 1
Name: Square
Shape ID: 2
Name: Rectangle
Shape ID: 3
Name: Dynamic connector
通过名称读取形状属性
您可以通过形状名称读取其属性。只需按照以下步骤操作:
- 加载图表文件。
- 访问页面。
- 通过名称查找形状。
- 用于Props读取属性。
下面是 Java 代码示例,演示了如何使用形状名称读取形状的属性:
// Load the Visio file
Diagram diagram = new Diagram("Drawing1.vsdx");
// Access the first page
Page page = diagram.getPages().get(0);
// Iterate through shapes
for (Shape shape : (Iterable<Shape>) page.getShapes()) {
// Read shape propert by name
if ("Process".equals(shape.getName())) {
for (Prop prop : (Iterable<Prop>) shape.getProps()) {
System.out.println("Property Name: " + prop.getLabel().getValue());
System.out.println("Value: " + prop.getValue().getVal());
}
}
}
读取 Java 中 Shape 的 InheritProps
您还可以按照以下步骤获取继承的形状属性:
- 打开 Visio 文件。
- 获取页面并循环浏览形状。
- 用于InheritProps读取继承的值。
以下示例 Java 代码展示了如何在 Java 中读取 Visio 形状的 InheritProps:
// Load the Visio file
Diagram diagram = new Diagram("Drawing1.vsdx");
// Access the first page
Page page = diagram.getPages().get(0);
// Iterate through shapes InheritProps
for (Shape shape : (Iterable<Shape>) page.getShapes()) {
for (Prop prop : (Iterable<Prop>) shape.getInheritProps()) {
System.out.println("Inherited Name: " + prop.getLabel().getValue());
System.out.println("Value: " + prop.getValue().getVal());
}
}
Java读取Visio形状数据教程

被折叠的 条评论
为什么被折叠?



