c语言如何解析.vsd(visio生成的图)文件

i0703mtf 2016-12-21 10:42:47
有没有可用的开源库来解析visio生成文件(.vsd/.vss/.vst等等),读取图中对应的对应关系。
谢谢!
...全文
473 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
i0703mtf 2017-01-05
  • 打赏
  • 举报
回复
Visio文件以.vss格式保存,可以直接使用记事本打开。 内容为xml文件格式,可以进行分析。
赵4老师 2016-12-21
  • 打赏
  • 举报
回复
在Visio中开始记录宏,手动完成所需功能,结束记录宏,按Alt+F11键,查看刚才记录的宏对应的VBA代码。 调用vba for Visio 参考C调用vba for excel:
// Copyright (C) 1992-1998 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Visual C++ Language  Reference and related
// electronic documentation provided with Microsoft Visual C++.
// See these sources for detailed information regarding the
// Microsoft Visual C++ product.

// NOTE: This example will only work with Excel8 in Office97
// Compile with cl /GX comexcel.cpp
// TO DO: Edit the #import paths
//#pragma message ("Make sure you go to Tools.Options.Directories and add the paths to mso97.dll and vbeext1.olb.  Mso97.dll will usually be in c:\\\"Program Files\"\\\"Microsoft Office\"\\Office, and vbeext1.olb will be in c:\\\"Program Files\"\\\"Common Files\"\\\"Microsoft Shared\"\\VBA")
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\Office11\\mso.dll" no_namespace rename("DocumentProperties", "DocumentPropertiesXL")
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\VBA6\\VBE6EXT.OLB" no_namespace
#import "C:\\Program Files\\Microsoft Office\\OFFICE11\\excel.exe" rename("DialogBox", "DialogBoxXL") rename("RGB", "RBGXL") rename("DocumentProperties", "DocumentPropertiesXL") no_dual_interfaces

#pragma warning (disable:4192 4146)

#include <stdio.h>
#include <tchar.h>

void dump_com_error(_com_error &e)
{
    _tprintf(_T("Oops - hit an error!\n"));
    _tprintf(_T("\a\tCode = %08lx\n"), e.Error());
    _tprintf(_T("\a\tCode meaning = %s\n"), e.ErrorMessage());
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    _tprintf(_T("\a\tSource = %s\n"), (LPCTSTR) bstrSource);
    _tprintf(_T("\a\tDescription = %s\n"), (LPCTSTR) bstrDescription);
}

// If this is placed in the scope of the smart pointers, they must be
// explicitly Release(d) before CoUninitialize() is called.  If any reference
// count is non-zero, a protection fault will occur.
struct StartOle
{
    StartOle() { CoInitialize(NULL); }
    ~StartOle() { CoUninitialize(); }
} _inst_StartOle;

void main()
{
    using namespace Excel;

    _ApplicationPtr pXL;

    try
    {
      pXL.CreateInstance(L"Excel.Application");

      pXL->Visible = VARIANT_TRUE;

      WorkbooksPtr pBooks = pXL->Workbooks;
      _WorkbookPtr pBook  = pBooks->Add((long)xlWorksheet);
      _WorksheetPtr pSheet = pXL->ActiveSheet;

      RangePtr pRange;
      pRange = pSheet->Range["A21"];
      pRange->Value2 = 75L;
      //pRange->NumberFormatLocal = "@";

      _CommandBarsPtr pCmdbars = pXL->CommandBars;
      int iCmdbars = pCmdbars->GetCount();

      Sleep(1000);
      pRange = pSheet->Range["20:20"];
      pRange->Insert( (long)Excel::xlDown );
      pRange->Merge();

      Sleep(1000);

      pBook->Saved = VARIANT_TRUE;
      pXL->Quit();
    }
    catch(_com_error &e)
    {
      dump_com_error(e);

      pXL->Quit();
    }
}


赵4老师 2016-12-21
  • 打赏
  • 举报
回复
YapingXin 2016-12-21
  • 打赏
  • 举报
回复
引用 2 楼 i0703mtf 的回复:
[quote=引用 1 楼 zhao4zhong1 的回复:] 在Visio中开始记录宏,手动完成所需功能,结束记录宏,按Alt+F11键,查看刚才记录的宏对应的VBA代码。 调用vba for Visio
我现在需要从文件内解析出图标对应的关系,例如图A链接了图B,不是想对现有的文件本身做操作,这种方式不可以吧[/quote] 我个人认为,你的这个开发需求实现起来十分复杂,我也没时间看这个东西,但我觉得你首先要阅读微软的相关的SDK说明,最好先从 MSDN 上找答案。
i0703mtf 2016-12-21
  • 打赏
  • 举报
回复
引用 1 楼 zhao4zhong1 的回复:
在Visio中开始记录宏,手动完成所需功能,结束记录宏,按Alt+F11键,查看刚才记录的宏对应的VBA代码。 调用vba for Visio
我现在需要从文件内解析出图标对应的关系,例如图A链接了图B,不是想对现有的文件本身做操作,这种方式不可以吧

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧