我有這個代碼可以創建一個新的Visio文檔並添加一個矩形。它的工作原理,但我不喜歡打開另一個文件從它獲得碩士學位。問題是新文檔有一個空的Masters形狀集合。我無法在Document類中找到將形狀添加到Masters集合中的方法,並且我可以找到用於添加形狀的所有示例(假定您擁有現有文檔)。有沒有更好的方式去做我想要的?將形狀添加到新的Visio文檔
// create the new application
Visio.Application va = new Microsoft.Office.Interop.Visio.Application();
// add a document
va.Documents.Add(@"");
// Visio.Documents vdocs = va.Documents;
// we need this document to get its Masters shapes collection
// since our new document has none
Visio.Document vu = vdocs.OpenEx(@"C:\Program Files (x86)\Microsoft Office\Office12\1033\Basic_U.vss", (short)Microsoft.Office.Interop.Visio.VisOpenSaveArgs.visOpenDocked);
// set the working document to our new document
Visio.Document vd = va.ActiveDocument;
// set the working page to the active page
Microsoft.Office.Interop.Visio.Page vp = va.ActivePage;
// if we try this from the Masters collection from our new document
// we get a run time since our masters collection is empty
Visio.Master vm = vu.Masters.get_ItemU(@"Rectangle");
Visio.Shape visioRectShape = vp.Drop(vm, 4.25, 5.5);
visioRectShape.Text = @"Rectangle text.";
謝謝。你知道一個體面的論壇和/或用於生成Visio文檔的一些好的資源嗎?我昨天花了幾個小時,大部分時間都在摸索着。我仍然有一些問題,比如如何確定形狀的連接點,以及如何解決特定的連接點? – 2012-02-28 13:27:59
查看這兩個鏈接 [分析過程流之間的連接 - VisGuy.com](http://www.visguy.com/2009/04/22/analyze-connectivity-between-process-flows/) [創建Visio流程圖程序化 - VisGuy.com](http://www.visguy.com/2006/09/13/create-visio-flowcharts-programmatically/) – JohnGoldsmith 2012-02-28 14:17:41
此外,沒有特定的順序: [Visio Automation - Saveen Reddy on CodePlex](http://visioautomation.codeplex.com/) [Visio Guy forum](http://visguy.com/vgforum/index.php) [TechNet](http://social.technet.microsoft。 com/Forums/en-AU/visiogeneral/threads) [開發Visio解決方案 - 舊的但很棒的資源](http://msdn.microsoft.com/zh-cn/library/aa245244%28office.10%29.aspx ) [Visio 2010 SDK]( http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=12365) 和一個全面的列表,我會看看[VisGuy.com上的鏈接部分](http ://www.visguy。com/visio-links /) – JohnGoldsmith 2012-02-28 14:18:19