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