C#VB.NET 在PPT中创建、编辑PPT SmartArt图形

C#VB.NET 在PPT中创建、编辑PPT SmartArt图形,第1张

概述本文介绍通过C#和VB.NET程序代码来创建编辑PPT文档中的SmartArt图形。文中将分两个 *** 作示例来演示创建和编辑结果。 使用工具:Spire.Presentation for .NET ho

本文介绍通过C#和VB.NET程序代码来创建和编辑PPT文档中的SmartArt图形。文中将分两个 *** 作示例来演示创建和编辑结果。

使用工具:Spire.Presentation for .NET hotfix 5.9.5

Dll文件引用:

方式1:下载包。下载后,解压,打开Bin文件夹,根据自己用的.NET Framework选择相应的文件夹,如:此示例中使用的是NET4.0,即打开NET4.0文件,找到Spire.Presentation.dll文件。找到dll文件后,在vs程序中添加引用该dll。

如下引用结果:

 

 

方式2:通过Nuget搜索下载导入。

 

 

注:创建SmartArt图形时,可创建80多种不同类型的图形,编辑图形是,可添加、删除节点、编辑节点内容、给节点内容设置超链接(包括链接到网页、链接到幻灯片)

示例1. 创建PPT SmartArt图形
using Spire.Presentation; Spire.Presentation.Diagrams;namespace AddSmartArt{    class Program    {        static voID Main(string[] args)        {            //实例化Presentation对象            Presentation ppt = new Presentation();            设置幻灯片大小            ppt.SlIDeSize.Type = SlIDeSizeType.Screen16x9;            添加组织结构图类型的SmartArt图形,并指定位置、大小            ISmartArt smartArt = ppt.SlIDes[0].Shapes.AppendSmartArt(100,50,1)">450,1)">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 = 总经理\nGeneral Manager;            node1_1_1.TextFrame.Text = 供应部\nSupply Dept.;            node1_1_2.TextFrame.Text = 营销部\nSales Dept.;            node1_1_3.TextFrame.Text = 生产部\nProductive Dept.;            node1_1_4.TextFrame.Text = 财务部\nFinance Dept.;            node1_1_5.TextFrame.Text = 人力资源部\nHR Dept.;            node1_1_6.TextFrame.Text = 质检中心\nQuality Center;            node1_1_1_1.TextFrame.Text = 采购部\nPurchase Dept.;            node1_1_1_2.TextFrame.Text = 仓库管理\nWarehouse Manager;            node1_1_1_3.TextFrame.Text = 物流部\nLogistics Dept.;            node1_1_3_1.TextFrame.Text = 生产车间\nProduction Dept.;            node1_1_3_2.TextFrame.Text = 维修部\nMaintenance Dept.;            node1_1_6_1.TextFrame.Text = 生产质量管理\nProduction Quality Mgt.;            node1_1_6_2.TextFrame.Text = 生产安全管理\nProduction Safety Mgt.;            node1_1_6_3.TextFrame.Text = 环境管理\nEnvironmental Mgt.;                        保存文档            ppt.Savetofile(result.pptx);        }    }}

图形创建结果:

VB.NET

imports Spire.Presentation Spire.Presentation.Diagramsnamespace AddSmartArt    Class Program        Private Shared Sub Main(args As String())            '实例化Presentation对象            Dim ppt New Presentation()             SlIDeSizeType.Screen16x9            添加组织结构图类型的SmartArt图形,并指定位置、大小            Dim smartArt As ISmartArt = ppt.SlIDes(0).Shapes.AppendSmartArt(750,1)">450 SmartArtStyleType.IntenceEffect            smartArt.colorStyle = SmartArtcolorType.colorfulAccentcolors3to4            For Each node As ISmartArtNode In smartArt.Nodes                smartArt.Nodes.RemoveNode(node)            Next            添加形状并在其下面添加嵌套子形状            Dim node1 As ISmartArtNode = smartArt.Nodes.AddNode()            Dim node1_1  node1.ChildNodes.AddNode()            Dim node1_1_1  node1_1.ChildNodes.AddNode()            Dim node1_1_2 Dim node1_1_3 Dim node1_1_4 Dim node1_1_5 Dim node1_1_6 Dim node1_1_1_1  node1_1_1.ChildNodes.AddNode()            Dim node1_1_1_2 Dim node1_1_1_3 Dim node1_1_3_1  node1_1_3.ChildNodes.AddNode()            Dim node1_1_3_2 Dim node1_1_6_1  node1_1_6.ChildNodes.AddNode()            Dim node1_1_6_2 Dim node1_1_6_3  node1_1_6.ChildNodes.AddNode()            董事会" & vbLf +             node1_1.TextFrame.Text = 总经理            node1_1_1.TextFrame.Text = 供应部            node1_1_2.TextFrame.Text = 营销部            node1_1_3.TextFrame.Text = 生产部            node1_1_4.TextFrame.Text = 财务部            node1_1_5.TextFrame.Text = 人力资源部            node1_1_6.TextFrame.Text = 质检中心            node1_1_1_1.TextFrame.Text = 采购部            node1_1_1_2.TextFrame.Text = 仓库管理            node1_1_1_3.TextFrame.Text = 物流部            node1_1_3_1.TextFrame.Text = 生产车间            node1_1_3_2.TextFrame.Text = 维修部            node1_1_6_1.TextFrame.Text = 生产质量管理            node1_1_6_2.TextFrame.Text = 生产安全管理            node1_1_6_3.TextFrame.Text = 环境管理"            )        End Sub    End ClassEnd namespace

 

示例2. 编辑PPT SmartArt图形
 ModifySmartArt{    加载PPT幻灯片文档            Presentation ppt =  Presentation();            ppt.LoadFromfile(test.pptx);            获取SmartArt图形的节点集合            ISmartArt smartart = ppt.SlIDes[0].Shapes[0] as ISmartArt;            ISmartArtNodeCollection nodes = smartart.Nodes;            更改节点内容            nodes[1].TextFrame.Text = 新修改的节点内容;            添加超链接到节点            nodes[2].Click = new ClickHyperlink(https://baike.baIDu.com/");添加指向网页的超链接            nodes[3].Click = new ClickHyperlink(ppt.SlIDes[1]);添加指向指定幻灯片的超链接            添加节点            ISmartArtNode newnode = nodes[5].ChildNodes.AddNode();            newnode.TextFrame.Text = 新添加的节点内容删除节点            nodes[0].ChildNodes[3].ChildNodes.RemoveNodeByposition(0);             保存到本地并打开            ppt.Savetofile(output.pptx);        }    }}

添加超链接后,注意要在幻灯片播放下才可见超链接添加效果:

 

VB.NET

 ModifySmartArt    加载PPT幻灯片文档             Presentation()            ppt.LoadFromfile()            获取SmartArt图形的节点集合            Dim smartart As ISmartArt = TryCast(ppt.SlIDes(0).Shapes(0),ISmartArt)            Dim nodes As ISmartArtNodeCollection = smartart.Nodes            更改节点内容            nodes(1).TextFrame.Text = "            添加超链接到节点            nodes(2).Click = New ClickHyperlink()            添加指向网页的超链接            nodes(3).Click = New ClickHyperlink(ppt.SlIDes(1))            添加指向指定幻灯片的超链接            添加节点            Dim newnode As ISmartArtNode = nodes().ChildNodes.AddNode()            newnode.TextFrame.Text = 删除节点            nodes[0].ChildNodes[3].ChildNodes.RemoveNodeByposition(0);             End namespace

 

总结

以上是内存溢出为你收集整理的C# / VB.NET 在PPT中创建、编辑PPT SmartArt图形全部内容,希望文章能够帮你解决C# / VB.NET 在PPT中创建、编辑PPT SmartArt图形所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1213434.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存