有没有一种方法可以在PowerPoint中将SmartArt与C#一起使用而无需调用SmartArtLayouts的应用程序?

问题描述

我正在尝试使用C#Windows窗体应用程序在PowerPoint中添加SmartArt。我发现以下代码仅在第二行为pptApplication.Presentations.Add(MsoTriState.msoTrue);时有效 我的用户习惯于在不打开的情况下在后台创建PPT,因此我想找到一种不必保持WithWindow为true的方法。这可能吗?

当前(如果WithWindow设置为false),我将收到错误System.Runtime.InteropServices.COMException:'应用程序(未知成员):对象不存在。在呼叫pptApplication.SmartArtLayouts[1]

的行上
  // Create the Presentation File
            Microsoft.Office.Interop.PowerPoint.Application pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoFalse);
            CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

            // Create new Slide
            var slides = pptPresentation.Slides;
            var slide = slides.AddSlide(1,customLayout);

            Microsoft.Office.Interop.PowerPoint.Shape shp = slide.Shapes.AddSmartArt(pptApplication.SmartArtLayouts[1],9,11);

            var smartshp = shp.SmartArt;
            var txtrg = smartshp.Nodes[1].TextFrame2.TextRange; 
            txtrg.Text = "test1";

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...