ms office的smartart功能可供用户一键生成各种逻辑图表、图形,常见的流程图、组织结构图都能用它搞定。spire.presentation提供了相应的接口ismartart来处理smartart图形,本文将介绍如何使用spire.presentation生成组织结构图。
c#
//实例化presentation对象
presentation ppt = new presentation();
//设置幻灯片大小
ppt.slidesize.type = slidesizetype.screen16x9;
//添加组织结构图,并指定位置、大小
ismartart smartart = ppt.slides[0].shapes.appendsmartart(50, 50, 450, 250, smartartlayouttype.organizationchart);
//设置smartart的样式和颜色
smartart.style = smartartstyletype.intenceeffect;
smartart.colorstyle = smartartcolortype.colorfulaccentcolors3to4;
//移除默认的形状(node即代表smartart中的形状)
foreach (ismartartnode node in smartart.nodes)
{
smartart.nodes.removenode(node);
}
//添加形状并在其下面添加嵌套子形状
ismartartnode node1 = smartart.nodes.addnode();
ismartartnode node1_1 = node1.childnodes.addnode();
ismartartnode node1_1_1 = node1_1.childnodes.addnode();
ismartartnode node1_1_2 = node1_1.childnodes.addnode();
ismartartnode node1_1_3 = node1_1.childnodes.addnode();
ismartartnode node1_1_4 = node1_1.childnodes.addnode();
ismartartnode node1_1_5 = node1_1.childnodes.addnode();
ismartartnode node1_1_6 = node1_1.childnodes.addnode();
ismartartnode node1_1_1_1 = node1_1_1.childnodes.addnode();
ismartartnode node1_1_1_2 = node1_1_1.childnodes.addnode();
ismartartnode node1_1_1_3 = node1_1_1.childnodes.addnode();
ismartartnode node1_1_3_1 = node1_1_3.childnodes.addnode();
ismartartnode node1_1_3_2 = node1_1_3.childnodes.addnode();
ismartartnode node1_1_6_1 = node1_1_6.childnodes.addnode();
ismartartnode node1_1_6_2 = node1_1_6.childnodes.addnode();
ismartartnode node1_1_6_3 = node1_1_6.childnodes.addnode();
//在每一个形状上添加文字
node1.textframe.text = "董事会\n" "board of directors";
node1_1.textframe.text = "总经理\n" "general manager";
node1_1_1.textframe.text = "供应部\n" "supply dept.";
node1_1_2.textframe.text = "营销部\n" "sales dept.";
node1_1_3.textframe.text = "生产部\n" "productive dept.";
node1_1_4.textframe.text = "财务部\n" "finance dept.";
node1_1_5.textframe.text = "人力资源部\n" "hr dept.";
node1_1_6.textframe.text = "质检中心\n" "quality center";
node1_1_1_1.textframe.text = "采购部\n" "purchase dept.";
node1_1_1_2.textframe.text = "仓库管理\n" "warehouse manager";
node1_1_1_3.textframe.text = "物流部\n" "logistics dept.";
node1_1_3_1.textframe.text = "生产车间\n" "production dept.";
node1_1_3_2.textframe.text = "维修部\n" "maintenance dept.";
node1_1_6_1.textframe.text = "生产质量管理\n" "production quality mgt.";
node1_1_6_2.textframe.text = "生产安全管理\n" "production safety mgt.";
node1_1_6_3.textframe.text = "环境管理\n" "environmental mgt.";
//保存文档
ppt.savetofile("output.pptx", fileformat.pptx2013);
vb.net
'实例化presentation对象
dim ppt as new presentation()
'设置幻灯片大小
ppt.slidesize.type = slidesizetype.screen16x9
'添加组织结构图,并指定位置、大小
dim smartart as ismartart = ppt.slides(0).shapes.appendsmartart(50, 50, 450, 250, smartartlayouttype.organizationchart)
'设置smartart的样式和颜色
smartart.style = smartartstyletype.intenceeffect
smartart.colorstyle = smartartcolortype.colorfulaccentcolors3to4
'移除默认的形状(node即代表smartart中的形状)
for each node as ismartartnode in smartart.nodes
smartart.nodes.removenode(node)
next
'添加形状并在其下面添加嵌套子形状
dim node1 as ismartartnode = smartart.nodes.addnode()
dim node1_1 as ismartartnode = node1.childnodes.addnode()
dim node1_1_1 as ismartartnode = node1_1.childnodes.addnode()
dim node1_1_2 as ismartartnode = node1_1.childnodes.addnode()
dim node1_1_3 as ismartartnode = node1_1.childnodes.addnode()
dim node1_1_4 as ismartartnode = node1_1.childnodes.addnode()
dim node1_1_5 as ismartartnode = node1_1.childnodes.addnode()
dim node1_1_6 as ismartartnode = node1_1.childnodes.addnode()
dim node1_1_1_1 as ismartartnode = node1_1_1.childnodes.addnode()
dim node1_1_1_2 as ismartartnode = node1_1_1.childnodes.addnode()
dim node1_1_1_3 as ismartartnode = node1_1_1.childnodes.addnode()
dim node1_1_3_1 as ismartartnode = node1_1_3.childnodes.addnode()
dim node1_1_3_2 as ismartartnode = node1_1_3.childnodes.addnode()
dim node1_1_6_1 as ismartartnode = node1_1_6.childnodes.addnode()
dim node1_1_6_2 as ismartartnode = node1_1_6.childnodes.addnode()
dim node1_1_6_3 as ismartartnode = node1_1_6.childnodes.addnode()
'在每一个形状上添加文字
node1.textframe.text = "董事会" & vblf "board of directors"
node1_1.textframe.text = "总经理" & vblf "general manager"
node1_1_1.textframe.text = "供应部" & vblf "supply dept."
node1_1_2.textframe.text = "营销部" & vblf "sales dept."
node1_1_3.textframe.text = "生产部" & vblf "productive dept."
node1_1_4.textframe.text = "财务部" & vblf "finance dept."
node1_1_5.textframe.text = "人力资源部" & vblf "hr dept."
node1_1_6.textframe.text = "质检中心" & vblf "quality center"
node1_1_1_1.textframe.text = "采购部" & vblf "purchase dept."
node1_1_1_2.textframe.text = "仓库管理" & vblf "warehouse manager"
node1_1_1_3.textframe.text = "物流部" & vblf "logistics dept."
node1_1_3_1.textframe.text = "生产车间" & vblf "production dept."
node1_1_3_2.textframe.text = "维修部" & vblf "maintenance dept."
node1_1_6_1.textframe.text = "生产质量管理" & vblf "production quality mgt."
node1_1_6_2.textframe.text = "生产安全管理" & vblf "production safety mgt."
node1_1_6_3.textframe.text = "环境管理" & vblf "environmental mgt."
'保存文档
ppt.savetofile("output.pptx", fileformat.pptx2013)