是否可以在 C# 中使用的 PowerPoint Interop 中以编程方式将幻灯片母版页选择到视图中,就像选择常规幻灯片一样?通过提供该母版页的 ID 或来自将其作为模板的幻灯片。
我设法将视图切换到幻灯片母版:
_pptApplication.ActiveWindow.ViewType = PpViewType.ppViewMasterThumbnails;
我尝试先选择一张幻灯片,然后切换到母版视图,但此指令始终将第一个幻灯片母版页置于视图中,而不是与所选幻灯片关联的那个。
同样,我想知道这对于笔记、讲义及其主人是否可行。
除了设置 .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();
}
}
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句