图表控件Aspose.Diagram教程:使用 Java 读取 Visio 形状数据

Java读取Visio形状数据教程
<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-diagram</artifactId>
    <version>25.7</version>
</dependency>

如何在 Java 中读取 Visio 形状数据

按照以下步骤从 Visio 文件读取形状数据:

  1. 使用该类加载文件Diagram。
  2. 从图表中获取一页。
  3. 循环遍历页面上的形状。
  4. 打印形状 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

通过名称读取形状属性

您可以通过形状名称读取其属性。只需按照以下步骤操作:

  1. 加载图表文件。
  2. 访问页面。
  3. 通过名称查找形状。
  4. 用于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

您还可以按照以下步骤获取继承的形状属性:

  1. 打开 Visio 文件。
  2. 获取页面并循环浏览形状。
  3. 用于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());
    }
}
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值