如何动态添加visio文件中的模板(C#)

时间:2013-05-28 14:35:27

标签: c# interop visio

我有一个Visio文档和一个Stencil(.vss)文件。要求:动态地在Visio文档中添加此模板文件。

    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吗?破解这个。

2 个答案:

答案 0 :(得分:0)

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

visioDocument = visioApplication.Documents.Open(fileName);

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

答案 1 :(得分: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);
            }
        }
   }