我如何阻止ppt在创建时自动打开

问题描述 投票:1回答:1

在此处输入代码,我正在使用office.interop.powerpoint创建powerpoint演示文稿,但问题是powerpoint演示文稿首先在前台打开,然后随着功能的进行添加幻灯片,最后保存文件。

我如何才能完全停止打开此Powerpoint应用程序,而是使所有进程都在后台运行,以便最终保存它。这有点类似的情况:

Application pptApplication = new Application();

Microsoft.Office.Interop.PowerPoint.Slides slides;
Microsoft.Office.Interop.PowerPoint._Slide slide;
Microsoft.Office.Interop.PowerPoint.TextRange objText;

// Create the Presentation File
Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

for(int i=0;i<4;i++){
        // Create new Slide
        slides = pptPresentation.Slides;
        slide = slides.AddSlide(1, customLayout);

        objText = slide.Shapes[2].TextFrame.TextRange;
        objText.Text = "Content goes here\nYou can add text\nItem 3";

        Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
        slide.Shapes.AddPicture(pictureFileName,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,shape.Left, shape.Top, shape.Width, shape.Height);


}

pptPresentation.SaveAs(@"c:\temp\fppt.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
//pptPresentation.Close();
//pptApplication.Quit();

当代码到达Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);时,powerpoint弹出窗口n然后将一张一张地创建所有幻灯片...

c# office-interop
1个回答
0
投票

您是否尝试将Presentations.Add(WithWindow)参数设置为msoFalse

Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoFalse);

将其设置为msoTrue会在可见窗口中创建演示。请参阅here

© www.soinside.com 2019 - 2024. All rights reserved.