0

I use NetOffice.PowerPointApi to play some Powerpoint-Slides of an existing PPTX. This is how this is done:

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();
}

Now my plan was to display slide 3 to 4.

But when I set the startingSlide (commented out in my example) I receive an error on powerApplication.ActivePresentation.SlideShowWindow.View.CurrentShowPosition :

{"SlideShowView.CurrentShowPosition : Invalid request. There is currently no slide show view for this presentation."}

This only happens when I set the property StartingSlide. If I don't, the presentation runs from the first until the 4th slide.

Ole Albers
  • 8,715
  • 10
  • 73
  • 166

1 Answers1

2

You need to set more properties of the SlideShowSettings object:

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();
            }
        }
    }
}
Jbjstam
  • 874
  • 6
  • 13
  • Surprisingly after over 2 years I had the same requirement again and you just answered that question correctly :) \o/ – Ole Albers Feb 14 '17 at 16:09
  • Haha, what a lucky coincidence that I should be randomly browsing all the NetOffice questions yesterday then :-) Good luck with your project! – Jbjstam Feb 14 '17 at 16:12