我正在尝试使用Java for Java来读取我的visio (vsdx)文件并提取形状、模板、连接器等信息。在examples/ aspose.diagram / shapes中,当我尝试使用代码中指定的文件运行retrieveShapeInfo类时,它不提取组/容器中存在的形状的信息。
这是我正在使用的github存储库的链接。我正在使用存储库中的com.aspose.diagram.examples/Shapes/RetriveShapeInfo https://github.com/aspose-diagram/Aspose.Diagram-for-Java类。
这是我的代码片段。
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
}
发布于 2020-03-24 23:47:57
我正在尝试解析组中的每个形状。这是代码片段。
// 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和name以及形状的文本。然而,代码片段不能提取容器/组中的所有形状。
以下是输出。形状ID :1名称:正方形。1添加的形状文本:亚马逊路线53
形状ID :2名称: Square.2。2添加的形状文本:AWS
Shape ID :3名称: Square.3。3添加的shape文本: CloudFRont分发
形状ID :4名称: Square.4。4添加的形状文本:S3
形状ID :5名称: Square.5。5添加的形状文本:AWS用户池
形状ID :6名称: Square.6。6添加的形状文本:AWS quicksight
形状ID :9名称:圆形。9添加的形状文本:AWS AWS极光
形状ID : 10名称:圆形。10添加的形状文本:红移
形状ID : 15名称:十六进制15添加的形状文本:Dynamo db
形状ID : 16名称:十六进制16来自形状的文本添加:亚马逊雅典娜
Shape ID : 36 Name : Text from shape added:逻辑层
父形状ID : 36父名称:
Shape ID : 18名称: Circle.18 shape文字添加:cloudWatch
父形状ID : 36父名称:
形状ID : 35名称:
https://stackoverflow.com/questions/60818260
复制相似问题