如何在 C# 中读取 Visio 文档内容
我的DLL库代码如下:
using System;
using IVisio=Microsoft.Office.Interop.Visio;
namespace Emix
{
public class Visio
{
protected String path;
public Visio(String path)
{
this.path = path;
}
public void open()
{
try
{
IVisio.Document doc = new IVisio.Application().Documents.Add(this.path);
Console.WriteLine("Number of pages: " + doc.Pages.Count);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
但是,这段代码打开Visio编辑器,然后显示文档中的页数。
是否可以在不打开 Visio 的情况下读取此文件内容?
My DLL library code is as follows:
using System;
using IVisio=Microsoft.Office.Interop.Visio;
namespace Emix
{
public class Visio
{
protected String path;
public Visio(String path)
{
this.path = path;
}
public void open()
{
try
{
IVisio.Document doc = new IVisio.Application().Documents.Add(this.path);
Console.WriteLine("Number of pages: " + doc.Pages.Count);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}
However, this code opens the Visio editor and then displays the number of pages in the document.
Is it possible to read this file content without opening the Visio?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是如何在 visio 中读取形状属性的程序...
上面的示例假设您有 Visio Primary Interop Assembly 安装在您的电脑上,并且您已在项目中包含 Microsoft.Office.Interop.Visio 的引用者。
我希望这会对您有所帮助......
This is the program for how to read shape properties in visio....
The above example assumes that you have the Visio Primary Interop Assembly installed on you PC and that you have included a referee to Microsoft.Office.Interop.Visio in your project.
I hope this will helps you ....
如果您使应用程序不可见,您将看不到新的 Visio 实例打开(仍然会有一个 Visio 实例在运行,只是不可见)
If you make the application invisible, you will not see the new instance of Visio opening (there will still be a instance of Visio running, just not a visible one)
查看如何使用 C# 在 Visio 上获取形状数据信息。它包含一些有关您的场景的有用信息
此< /a> 帖子还解释了如何获取所有形状以及如何将所有形状连接在一起
Take a look at How to get shape data information on Visio with C#. It contains some useful information regarding your scenario
This post also explains how to get all shapes and additionally how to connect all shapes togather
正如其他答案之一指出的那样,您可以使用 Application.Visible 属性来隐藏正在运行的 Visio 实例。
您的另一个选择是直接读取 Visio 的 VDX 文件格式来检索页数、自定义属性等。这避免了必须启动 Visio 才能从文件中读取信息。但此解决方案确实需要您成为 VDX 的文件 XML 模式。
As one of the other answers points out you can use the Application.Visible property to hide the running instance of Visio.
Another option for you is to read the Visio's VDX file format directly to retrieve the number of pages, custom properties, etc. This avoids have to start Visio to read information from the file. But this solution does require you to become the VDX's files XML schema.
正如其他答案之一指出的那样,您可以使用 Application.Visible 属性来隐藏正在运行的 Visio 实例。
您的另一个选择是直接读取 Visio 的 VDX 文件格式来检索页数、自定义属性等。这避免了必须启动 Visio 才能从文件中读取信息。但此解决方案确实需要您成为 VDX 的文件 XML 模式。
As one of the other answers points out you can use the Application.Visible property to hide the running instance of Visio.
Another option for you is to read the Visio's VDX file format directly to retrieve the number of pages, custom properties, etc. This avoids have to start Visio to read information from the file. But this solution does require you to become the VDX's files XML schema.