如何创建一个新的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中的方法完全相同。
虽然你的答案是赞赏,并可能解决问题,建议不要发布这样的“仅链接”答案。该链接将来可能无效,使您的答案无用。相反,请考虑从适用于原始问题的链接中复制一些相关代码并详细说明工作原理。 –