|
5#
楼主 |
发表于 2014-4-11 20:46:42
|
只看该作者
本帖最后由 tianping 于 2014-4-11 20:55 编辑
visio2013项目需要引用两个类库(com组件):
Microsoft Office 15.0 Object Library 和 Microsoft Visio 15.0 Type Library
打开文件代码:
-
- using System;
- public sealed class OpenDocument
- {
- private OpenDocument()
- {
- }
- //applicationObj visio实例
- //stencilName 模具文件
- // documentName 绘图文件1
- // hiddenDocumentName 绘图文件2,将以隐藏方式打开,且不会显示在最近打开文件表里
- public static bool DemoDocumentOpen(
- Microsoft.Office.Interop.Visio.Application applicationObj,
- string stencilName,
- string documentName,
- string hiddenDocumentName)
- {
- bool documentsOpened = false;
- if (applicationObj == null)
- {
- return false;
- }
- try
- {
- //要求三个文件全部存在,文件要求全路径名
- if ((System.IO.File.Exists(stencilName)) &&
- (System.IO.File.Exists(documentName)) &&
- (System.IO.File.Exists(hiddenDocumentName)))
- {
- //OpenEx带两个参数,第一个是文件名,第二个是枚举参数,表示打开方式
- applicationObj.Documents.OpenEx(stencilName,
- ((short)Microsoft.Office.Interop.Visio.
- VisOpenSaveArgs.visOpenDocked + //停靠
- (short)Microsoft.Office.Interop.Visio.
- VisOpenSaveArgs.visOpenRO)); //只读
- applicationObj.Documents.OpenEx(documentName,
- (short)Microsoft.Office.Interop.Visio.
- VisOpenSaveArgs.visOpenCopy); //打开原文件复本
- applicationObj.Documents.OpenEx(hiddenDocumentName,
- ((short)Microsoft.Office.Interop.Visio.
- VisOpenSaveArgs.visOpenHidden + //隐藏
- (short)Microsoft.Office.Interop.Visio.
- VisOpenSaveArgs.visOpenMacrosDisabled + //禁用宏
- (short)Microsoft.Office.Interop.Visio.
- VisOpenSaveArgs.visOpenDontList)); //不加入最近文件表
- documentsOpened = true;
- }
- }
- catch (Exception error)
- {
- System.Diagnostics.Debug.WriteLine(error.Message);
- throw;
- }
- return documentsOpened;
- }
- }
复制代码
|
|