如何使用C#interop库在PowerPoint中设置演示文稿页面大小?

如何使用C#interop库在PowerPoint中设置演示文稿页面大小?,c#,powerpoint,office-interop,C#,Powerpoint,Office Interop,如何使用C#interop库设置PowerPoint中的演示文稿或幻灯片(PPT)页面大小 我想将演示文稿页面大小设置为“ppSlideSizeOnScreen16x9” 这个结果不是我所期望的; 现在,如何设置演示文稿或幻灯片(PPT)页面大小 不确定这是否正是您想要的,但这是我设置幻灯片大小的方式 this.Application.ActivePresentation.PageSetup.SlideHeight = <your slide height>; this.Applic

如何使用C#interop库设置PowerPoint中的演示文稿或幻灯片(PPT)页面大小

我想将演示文稿页面大小设置为“ppSlideSizeOnScreen16x9

这个结果不是我所期望的;
现在,如何设置演示文稿或幻灯片(PPT)页面大小

不确定这是否正是您想要的,但这是我设置幻灯片大小的方式

this.Application.ActivePresentation.PageSetup.SlideHeight = <your slide height>;
this.Application.ActivePresentation.PageSetup.SlideWidth = <your slide width>;

现在,这是正确的代码:

        PowerPoint.Application pptApp = new PowerPoint.Application();
        MyPres = pptApp.Presentations.Add(MsoTriState.msoTrue);
        MyPres.PageSetup.SlideWidth = <slide width>;
        MyPres.PageSetup.SlideHeight = <slide height >;

试着运行你的代码。错误消息为“请求无效。没有活动的演示文稿”。为什么?您在创建演示文稿后尝试了该代码?我在创建演示文稿并且幻灯片可见时运行它。然后,它会调整幻灯片的大小,并进行后续调整slides@Sandwich谢谢你的帮助,我发现了问题,正是这行代码不能达到预期的效果,我改了其他的way@Sandwich你能告诉我“72”是从哪里来的吗?这有什么意义?
private int PixelsToPoints(int pixels)
{
     return pixels * 72 / 96;
}
        PowerPoint.Application pptApp = new PowerPoint.Application();
        MyPres = pptApp.Presentations.Add(MsoTriState.msoTrue);
        MyPres.PageSetup.SlideWidth = <slide width>;
        MyPres.PageSetup.SlideHeight = <slide height >;
        MyPres.PageSetup.SlideSize = PowerPoint.PpSlideSizeType.ppSlideSizeOnScreen16x9;