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

时间:2020-08-17 21:32:49

标签: c# .net office-interop office-automation

我正在尝试使用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";

0 个答案:

没有答案
相关问题