Wiki
Clone wikiAspose for OpenXML / Count the number of Slides
OpenXML SDK
class Program { static void Main(string[] args) { Console.WriteLine("Number of slides = {0}", CountSlides("Count the number of slides.pptx")); Console.ReadKey(); } // Get the presentation object and pass it to the next CountSlides method. public static int CountSlides(string presentationFile) { // Open the presentation as read-only. using (PresentationDocument presentationDocument = PresentationDocument.Open(presentationFile, false)) { // Pass the presentation to the next CountSlide method // and return the slide count. return CountSlides(presentationDocument); } } // Count the slides in the presentation. public static int CountSlides(PresentationDocument presentationDocument) { // Check for a null document object. if (presentationDocument == null) { throw new ArgumentNullException("presentationDocument"); } int slidesCount = 0; // Get the presentation part of document. PresentationPart presentationPart = presentationDocument.PresentationPart; // Get the slide count from the SlideParts. if (presentationPart != null) { slidesCount = presentationPart.SlideParts.Count(); } // Return the slide count to the previous method. return slidesCount; } }
Aspose.Slides
class Program { static void Main(string[] args) { Console.WriteLine("Number of slides = {0}", CountSlides("Count the number of slides.pptx")); Console.ReadKey(); } public static int CountSlides(string presentationFile) { //Instantiate a PresentationEx object that represents a PPTX file using (PresentationEx pres = new PresentationEx(presentationFile)) { return pres.Slides.Count; } } }
Download
Updated