2014-02-12 136 views
0

我需要在我的Visio文件中添加一個矩形並設置字體和文本顏色, 我該如何做到這一點?如何在Visio中設置形狀,字體和前景色

visio.Application app = new visio.Application(); 
visio.Document doc; 
doc = app.Documents.Open(processPath); 

visio.Page page = doc.Pages[1]; 
CreateVisio vis = new CreateVisio(); 
visio.Shape edit = page.DrawRectangle(3.2d, 6.9d, 4.9d, 7.9d); 

回答

2

如何創建一個新的Visio文檔

Microsoft.Office.Interop.Visio.Application application = 
     new Microsoft.Office.Interop.Visio.Application(); 
application.Visible = false; 
Microsoft.Office.Interop.Visio.Document doc = application.Documents.Add(templatePath); 
Microsoft.Office.Interop.Visio.Page page = application.Documents[1].Pages[1]; 

如何獲取寬度和高度您正在使用

double xPosition = page.PageSheet.get_CellsU("PageWidth").ResultIU; 
double yPosition = page.PageSheet.get_CellsU("PageHeight").ResultIU; 

我們正在使用關於紙張寬度和高度的此信息知道將紙盒放在哪裏。我們通過將紙張寬度除以根數來將根盒放在紙張的中間。此外,我們正在從yPosition中減去級別編號,使得級別編號遞增的方框在圖表上的位置會較低。

如何創建形狀,並把它放在圖表(住嘴)

//creating the type of shape in the organizational chart it could be: "Position", 
//"Executive", "Manager", "Assistant" and others according 
//to what you have in your stencil. 
Microsoft.Office.Interop.Visio.Master position = doc.Masters.get_ItemU("Position"); 
//placing the shape in the xPosition and yPosition coordinates 
Microsoft.Office.Interop.Visio.Shape shape = page.Drop(position, xPosition, yPosition); 

如何設置形狀屬性

//set the text 
shape.Text = box.Name; 

//set hyperlink 
if (!String.IsNullOrEmpty(box.HyperLink.Trim())) 
{ 
    Hyperlink link = shape.Hyperlinks.Add(); 
    link.Address = box.HyperLink; 
} 

//set the shape width 
shape.get_CellsSRC(
       (short)Microsoft.Office.Interop.Visio.VisSectionIndices. 
       visSectionObject, 
       (short)Microsoft.Office.Interop.Visio.VisRowIndices. 
       visRowXFormIn, 
       (short)Microsoft.Office.Interop.Visio.VisCellIndices. 
       visXFormWidth).ResultIU = box.Width; 

//set the shape height 
shape.get_CellsSRC(
       (short)Microsoft.Office.Interop.Visio.VisSectionIndices. 
       visSectionObject, 
       (short)Microsoft.Office.Interop.Visio.VisRowIndices. 
       visRowXFormIn, 
       (short)Microsoft.Office.Interop.Visio.VisCellIndices. 
       visXFormHeight).ResultIU = box.Height; 

//set the shape fore color 
shape.Characters.set_CharProps(
       (short)Microsoft.Office.Interop.Visio. 
        VisCellIndices.visCharacterColor, 
       (short)Utilities.GetVisioColor(box.ForeColor)); 

//set the shape back color 
shape.get_CellsSRC((short)VisSectionIndices.visSectionObject, 
     (short)VisRowIndices.visRowFill, 
    (short)VisCellIndices.visFillForegnd).FormulaU = 
    "RGB(" + box.BackColor.R.ToString() + "," + box.BackColor.G.ToString() + "," 
    + box.BackColor.B.ToString() + ")"; 

連接形狀使用完成方法connectWithDynamicGlueAndConnector()。此方法接受兩個參數,即父級形狀和childShape,並將在兩者之間創建連接器。該方法與VISIO SDK中的方法完全相同。

0

您好,我發現這個問題的答案在這個環節

http://www.codeproject.com/Articles/109558/Creating-VISIO-Organigrams-using-C

+1

雖然你的答案是讚賞,並可能解決問題,建議不要發佈這樣的「僅鏈接」答案。該鏈接將來可能無效,使您的答案無用。相反,請考慮從適用於原始問題的鏈接中複製一些相關代碼並詳細說明工作原理。 –

相關問題