Select 使用 PowerPoint Interop 查看幻灯片母版页

Select into view a slide master page with PowerPoint Interop

是否可以在 C# 中使用的 PowerPoint Interop 中以编程方式 select 将幻灯片母版页显示在视图中,就像 select 普通幻灯片一样?通过提供该母版页的 ID 或从将其作为模板的幻灯片中获得。

我设法将视图切换到幻灯片母版:

_pptApplication.ActiveWindow.ViewType = PpViewType.ppViewMasterThumbnails;

我尝试先 select 制作一张幻灯片,然后切换到母版视图,但这条指令总是将第一张幻灯片母版页放在视图中,而不是与 select 幻灯片关联的那个.

同样,我想知道这是否适用于笔记、讲义及其母版。

除了设置 .ViewType 之外,您还需要在 CustomLayout 对象上使用 .Select() 方法。

这里有两个例子:

using NetOffice.OfficeApi.Enums;
using NetOffice.PowerPointApi.Enums;
using System;
using PowerPoint = NetOffice.PowerPointApi;

namespace ExportSlides
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var app = PowerPoint.Application.GetActiveInstance())
            {
                SelectSlideMasterLayoutOfActiveSlide(app);
                ActiveSlideMasterLayoutByIndex(app.ActivePresentation, 4);
            }
        }

        private static void ActiveSlideMasterLayoutByIndex(PowerPoint.Presentation activePresentation, int customLayoutIndex)
        {
            activePresentation.Windows[1].ViewType = PpViewType.ppViewSlideMaster; //PpViewType.ppViewMasterThumbnails doesn't work for me for some reason
            activePresentation.SlideMaster.CustomLayouts[customLayoutIndex].Select();
        }

        private static void SelectSlideMasterLayoutOfActiveSlide(PowerPoint.Application app)
        {
            var activeWindow = app.ActiveWindow;

            var slideObj = activeWindow.View.Slide;

            if (slideObj.GetType() == typeof(PowerPoint.Slide))
            {
                var slide = (PowerPoint.Slide)slideObj;

                activeWindow.ViewType = PpViewType.ppViewSlideMaster; //PpViewType.ppViewMasterThumbnails doesn't work for me for some reason

                slide.CustomLayout.Select();

            }
        }
    }
}