java导入visio文件

String filePath = "E:/桌面/cesgi.vsdx";
        File file = new File(filePath);
        XmlVisioDocument xmlVisioDocument = new XmlVisioDocument(new FileInputStream(file));
        Collection<XDGFPage> pages = xmlVisioDocument.getPages();
        Iterator<XDGFPage> iterator = pages.iterator();
        //存储所有连线起点的集合
        List<String> startLine = new ArrayList<>();
        //存储所有连线起点的集合
        List<String> endLine = new ArrayList<>();
        //存储所有形状id和文字的集合
        HashMap<String, String> idAndName = new HashMap<>();
        //存储所有形状id和样式的集合
        HashMap<String, String> idAndStyle = new HashMap<>();
        //存储所有形状id和宽高的集合
        HashMap<String, String> idAndSize = new HashMap<>();
         while (iterator.hasNext()) {
            XDGFPage xdgfPage = iterator.next();
            XDGFPageContents content = xdgfPage.getContent();

            //所有包含文字的形状节点
            Collection<XDGFShape> shapes = content.getShapes();
            Iterator<XDGFShape> iterator1 = shapes.iterator();

         

            while (iterator1.hasNext()) {
                XDGFShape xdgfShape = iterator1.next();
                if (xdgfShape.hasText() && !xdgfShape.getText().getTextContent().equals("")) {
                    //存储文字
                    idAndName.put(Long.toString(xdgfShape.getID()), xdgfShape.getTextAsString());
                    //存储形状类型
          
                    idAndStyle.put(Long.toString(xdgfShape.getID()), xdgfShape.getName());
                    //存储形状数据,xml结构中*100为业务需要
                    idAndSize.put(Long.toString(xdgfShape.getID()), " <style x=\"" + Math.round(xdgfShape.getPinX() * 100) +
                            "\" y=\"" + Math.round(xdgfShape.getPinY() * 100) +
                            "\" width=\"" + Math.round(xdgfShape.getWidth() * 100) +
                            "\" height=\"" + Math.round(xdgfShape.getHeight() * 100) +
                            "\" as=\"style\"/>");
            }
        

可以实现对vsdx文件的实时读取,解析,将数据转化为自定义xml

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值