我正在尝试使用Java的aspose.diagram API来读取我的visio(vsdx)文件,并提取形状,模具,连接器等的信息。在示例/图表/形状中,当我尝试使用代码中指定的文件,它不会提取组/容器中存在的形状信息。

这是我正在使用的github存储库的链接。
https://github.com/aspose-diagram/Aspose.Diagram-for-Java
我正在使用存储库中的com.aspose.diagram.examples / Shapes / RetriveShapeInfo Java类。

The image contains the diagram with a group. In the code, the shapes inside the group are not extracted

这是我的代码段。



public static void main(String[] args) throws Exception
	{
		// ExStart:RetrieveShapeInfo
		// The path to the documents directory.
		String dataDir = Utils.getSharedDataDir(RetrieveShapeInfo.class) + "Shapes/";

		// Load diagram
		//Diagram diagram = new Diagram(dataDir + "RetrieveShapeInfo.vsd");
		Diagram diagram = new Diagram(dataDir + "filename.vsdx");

		System.out.println(diagram.getPages().getPage(0).getShapes().getCount());
        //List<Shape> ignoredShapes = new List<Shape>();
		for (com.aspose.diagram.Shape shape : (Iterable<Shape>) diagram.getPages().getPage(0).getShapes())
		{

			// Display information about the shapes
			System.out.println("\nShape ID : " + shape.getID());
			System.out.println("Name : " + shape.getName());
			if(shape.getMaster() != null)
			    System.out.println("Master Shape : " + shape.getMaster().getName());

			// ExEnd:RetrieveShapeInfo
		}

最佳答案

我正在尝试解析组中的每个形状。这是代码段。

// for group shapes
            if(shape.getType()==TypeValue.GROUP)
                for (com.aspose.diagram.Shape subshape : (Iterable<com.aspose.diagram.Shape>) shape.getShapes()) {
                    System.out.println("\nParent Shape ID : " + shape.getID());
                    System.out.println("Parent Name : " + shape.getName());
                    System.out.println("\nShape ID : " + subshape.getID());
                    System.out.println("Name : " + subshape.getName());

                    //System.out.println(shape.getShapes().getCount());
                    if (subshape.getText().getValue().getText() != "") {
                        txt = (subshape.getText().getValue().getText().replaceAll("\\<.*?>", ""));
                        System.out.println("Text from shape added : " + txt);
                        txt += txt;
                    }


此代码段解析组形状,并返回父ID,名称和子形状ID和名称以及形状文本。但是,该摘要无法提取容器/组内的所有形状。

这是输出。
形状ID:1
名称:Square.1
形状文字已添加:亚马逊路线53

形状ID:2
名称:Square.2
形状文字已添加:AWS WAF

形状ID:3
名称:Square.3
形状文字已添加:CloudFRont分布

形状ID:4
名称:Square.4
形状文字已添加:S3

形状ID:5
名称:Square.5
添加了来自形状的文本:AWS Cognito用户池

形状ID:6
名称:Square.6
形状文字已添加:AWS快速见解

形状ID:9
名称:Circle.9
形状中的文字已添加:AWS Aurora

形状ID:10
名称:Circle.10
形状中的文字已添加:Redshift

形状ID:15
名称:Hexagon.15
来自形状的文本已添加:Dynamo数据库

形状ID:16
名称:Hexagon.16
形状文字已添加:Amazon Athena

形状ID:36
名称 :
形状中添加的文本:逻辑层


父形状ID:36
父母名字 :

形状ID:18
名称:Circle.18
形状中的文字已添加:cloudWatch

父形状ID:36
父母名字 :

形状ID:35
名称 :

09-11 04:52
查看更多