2013-05-28 45 views
0

我有一個Visio文檔和一個模具(.vss)文件。要求:動態地將此模板文件添加到Visio文檔中。如何在Visio文件中動態添加模具(C#)

private static void InsertStencilsToVisio() 
    {   
     string fileName = @"C:\Visio Files\TestVisio.vdw"; 
     if (System.IO.File.Exists(fileName)) 
     { 
      visioDocument = visioApplication.Documents.Open(fileName); 
      visioPage = visioApplication.Window.Application.ActivePage; 
      eswStencilDocument = visioPage.Application.Documents["eswstencil.vss"]; 
      CreateShapes(); 
     } 
    } 

我可以使用VisOpenSaveArgs嗎?破解這個。

回答

0

是的,你可以使用visOpenRO + visOpenDocked:

visioDocument = visioApplication.Documents.Open(fileName); 

visioApplication.Documents.OpenEx("eswstencil.vss", 
    (short)VisOpenSaveArgs.visOpenRO|(short)VisOpenSaveArgs.visOpenDocked); 
+0

嗨尼古拉,謝謝你的建議。我已經嘗試過了。 (簡稱)VisOpenSaveArgs.visOpenRO:僅以只讀模式打開模板。在這種情況下,它只是打開一個新的模具窗口以及一個visio文檔,這會導致額外的開銷,同時保存。準確的將模板添加到Visio文件是(簡稱)VisOpenSaveArgs.visOpenDocked。 – siva

0

由我自己解決了。在這裏,我打開Visio文檔,並在打開它的同時動態地將模具停靠在visio上。隨後該文件用模板保存。

private static void InsertStencilsToVisio() 
    { visioApplication = new Application(); 
     string fileName = @"C:\siva\CreateGen1Visio\pd-m-0001_1.11.vdw"; 
     string stencilFileName = @"C:\siva\CreateGen1Visio\eswstencil.vss"; 

     try 
     { 
      if (System.IO.File.Exists(fileName)) 
      { 
       visioDocument = visioApplication.Documents.OpenEx(fileName, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDontList); 
       visioPage = visioDocument.Application.ActivePage; 
       visioPage.Application.Documents.OpenEx(stencilFileName, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked); 
       visioDocument.SaveAsEx(fileName, (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visSaveAsWS); 
      } 
     } 
    } 
相關問題