是否可以在使用C#的PowerPoint Interop中以编程方式选择幻灯片母版页进入视图,就像您选择常规幻灯片一样?通过提供该母版页的ID或将其作为模板的幻灯片。
我设法将视图切换到幻灯片母版:
_pptApplication.ActiveWindow.ViewType = PpViewType.ppViewMasterThumbnails;
我首先尝试选择幻灯片,然后切换到主视图,但此指令始终会查看第一张幻灯片母版页,而不是与所选幻灯片相关联的图片。
同样,我想知道这是否适用于笔记,讲义及其主人。
答案 0 :(得分:1)
除了设置.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();
}
}
}
}