除了設置.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();
}
}
}
}
謝謝,我不知道'CustomLayout'的關鍵是這個。但有一種說法:當我嘗試這樣做時,在比較'slideObj.GetType()== typeof(PowerPoint.Slide)'時不起作用,而是必須將'activeWindow.View.Slide'投射到'Slide',然後有效。 –
還有一個問題:我注意到,按索引選擇時,您無法選擇第一張幻燈片母版頁。有沒有類似的方法來實現這一目標? –
我想如果你選擇ViewType,你會自動到達那裏,如果我記得正確的話,所以試着將值設置爲別的東西然後回來......這是否工作? – Jbjstam