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.

1 Answer 1

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();
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Surprisingly after over 2 years I had the same requirement again and you just answered that question correctly :) \o/
Haha, what a lucky coincidence that I should be randomly browsing all the NetOffice questions yesterday then :-) Good luck with your project!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.