Access Slide in PowerPoint Add-in

I am creating an add-in for PowerPoint and you need to access the objects of slides or slides or even the entire presentation; alas, the only way I can do this is to open a new ppt file. Right now I have to resort to the hacker method of saving the current presentation and reopening it with Packaging in order to manipulate something (more precisely, I need the SHA Slide objects from the pptx file to see if they changed - not perfect)

Is there a way to open a file that is currently open in PowerPoint without entering an IO file?

Thanks for your help, P

+4
source share
1 answer

I assume that you have created a PowerPoint add-in project (2007/2010) in VisualStudio. In general, you can access the active view with the static Globals class as follows:

 Globals.ThisAddIn.Application.ActivePresentation.Slides[slideIndex] ... 

Edit: Usage example:

 using PowerPoint = Microsoft.Office.Interop.PowerPoint; ... try { int numberOfSlides = Globals.ThisAddIn .Application.ActivePresentation.Slides.Count; if (numberOfSlides > 0) { // get first slide PowerPoint.Slide firstSlide = Globals.ThisAddIn .Application.ActivePresentation.Slides[0]; // get first shape (object) in the slide int shapeCount = firstSlide.Shapes.Count; if (shapeCount > 0) { PowerPoint.Shape firstShape = firstSlide.Shapes[0]; } // add a label PowerPoint.Shape label = firstSlide.Shapes.AddLabel( Orientation: Microsoft.Office.Core .MsoTextOrientation.msoTextOrientationHorizontal, Left: 100, Top: 100, Width: 200, Height: 100); // write hello world with a slidenumber label.TextFrame.TextRange.Text = "Hello World! Page: "; label.TextFrame.TextRange.InsertSlideNumber(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Error: " + ex); } 
0
source

Source: https://habr.com/ru/post/1437356/


All Articles