使用 PowerPoint 设置要显示的第一张幻灯片-Api
Setting first slide to display using PowerPoint-Api
我使用 NetOffice.PowerPointApi 播放现有 PPTX 的一些 Powerpoint 幻灯片。这是如何完成的:
PowerPoint.Application powerApplication = new PowerPoint.Application();
PowerPoint.Presentation presentation = powerApplication.Presentations.Open("C:\dev\test.pptx", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoTrue);
// presentation.SlideShowSettings.StartingSlide = 2;
presentation.SlideShowSettings.Run();
while (powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition < 4)
{
System.Threading.Thread.Sleep(2000);
powerApplication.ActivePresentation.SlideShowWindow.View.Next();
}
现在我的计划是放映幻灯片 3 到 4。
但是当我设置 startingSlide(在我的示例中被注释掉)时,我在 powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition
上收到错误:
{"SlideShowView.CurrentShowPosition : Invalid request. There is
currently no slide show view for this presentation."}
只有当我设置 属性 StartingSlide
时才会发生这种情况。如果我不这样做,演示文稿将从第一张幻灯片一直运行到第四张幻灯片。
您需要设置 SlideShowSettings 对象的更多属性:
using NetOffice.OfficeApi.Enums;
using NetOffice.PowerPointApi.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PowerPoint = NetOffice.PowerPointApi;
namespace PlayPowerPoint
{
class Program
{
static void Main(string[] args)
{
using (var app = new PowerPoint.Application())
{
var presentation = app.Presentations.Open(Path.GetFullPath("Test.pptx"), MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
var slideShowSettings = presentation.SlideShowSettings;
slideShowSettings.StartingSlide = 2;
slideShowSettings.EndingSlide = 4;
slideShowSettings.RangeType = PpSlideShowRangeType.ppShowSlideRange;
slideShowSettings.AdvanceMode = PpSlideShowAdvanceMode.ppSlideShowManualAdvance;
slideShowSettings.Run();
var slideShowView = presentation.SlideShowWindow.View;
while (slideShowView.CurrentShowPosition < slideShowSettings.EndingSlide)
{
Thread.Sleep(2000);
slideShowView.Next();
}
presentation.Saved = MsoTriState.msoTrue;
presentation.Close();
app.Quit();
}
}
}
}
我使用 NetOffice.PowerPointApi 播放现有 PPTX 的一些 Powerpoint 幻灯片。这是如何完成的:
PowerPoint.Application powerApplication = new PowerPoint.Application();
PowerPoint.Presentation presentation = powerApplication.Presentations.Open("C:\dev\test.pptx", MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoTrue);
// presentation.SlideShowSettings.StartingSlide = 2;
presentation.SlideShowSettings.Run();
while (powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition < 4)
{
System.Threading.Thread.Sleep(2000);
powerApplication.ActivePresentation.SlideShowWindow.View.Next();
}
现在我的计划是放映幻灯片 3 到 4。
但是当我设置 startingSlide(在我的示例中被注释掉)时,我在 powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition
上收到错误:
{"SlideShowView.CurrentShowPosition : Invalid request. There is currently no slide show view for this presentation."}
只有当我设置 属性 StartingSlide
时才会发生这种情况。如果我不这样做,演示文稿将从第一张幻灯片一直运行到第四张幻灯片。
您需要设置 SlideShowSettings 对象的更多属性:
using NetOffice.OfficeApi.Enums;
using NetOffice.PowerPointApi.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using PowerPoint = NetOffice.PowerPointApi;
namespace PlayPowerPoint
{
class Program
{
static void Main(string[] args)
{
using (var app = new PowerPoint.Application())
{
var presentation = app.Presentations.Open(Path.GetFullPath("Test.pptx"), MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
var slideShowSettings = presentation.SlideShowSettings;
slideShowSettings.StartingSlide = 2;
slideShowSettings.EndingSlide = 4;
slideShowSettings.RangeType = PpSlideShowRangeType.ppShowSlideRange;
slideShowSettings.AdvanceMode = PpSlideShowAdvanceMode.ppSlideShowManualAdvance;
slideShowSettings.Run();
var slideShowView = presentation.SlideShowWindow.View;
while (slideShowView.CurrentShowPosition < slideShowSettings.EndingSlide)
{
Thread.Sleep(2000);
slideShowView.Next();
}
presentation.Saved = MsoTriState.msoTrue;
presentation.Close();
app.Quit();
}
}
}
}