public void newslide()
 {
     try
     {
         if (Globals.ThisAddIn.Application.ActiveWindow.Active == Office.MsoTriState.msoTrue)
         {
             PowerPoint.View         view         = Globals.ThisAddIn.Application.ActiveWindow.View;
             PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
             if (presentation.Slides.Count > 0)
             {
                 PowerPoint.Slide slide = (PowerPoint.Slide)view.Slide;
                 presentation.Slides.AddSlide(slide.SlideIndex + 1, presentation.SlideMaster.CustomLayouts._Index(PowerPoint.PpSlideLayout.ppLayoutTitle.GetHashCode()));
                 presentation.Slides[slide.SlideIndex + 1].Select();
             }
             else
             {
                 presentation.Slides.AddSlide(1, presentation.SlideMaster.CustomLayouts._Index(PowerPoint.PpSlideLayout.ppLayoutTitle.GetHashCode()));
                 //presentation.Slides[0].Select();
             }
         }
     }
     catch (Exception)
     {
         // throw;
     }
 }
示例#2
0
        private void editBoxGoToSlide_TextChanged(object sender, RibbonControlEventArgs e)
        {
            try
            {
                PowerPoint.View view = Globals.ThisAddIn.Application.ActiveWindow.View;
                string          slideNumberString = editBoxGoToSlide.Text;
                ToolsSelection.GoToSlide(view, slideNumberString);

                editBoxGoToSlide.Text = "";
            }
            catch (Exception ex)
            {
                Exceptions.Handle(ex);
            }
        }
 public void deleteslide()
 {
     try
     {
         if (Globals.ThisAddIn.Application.ActiveWindow.Active == Office.MsoTriState.msoTrue)
         {
             PowerPoint.View         view         = Globals.ThisAddIn.Application.ActiveWindow.View;
             PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
             PowerPoint.Slide        slide        = (PowerPoint.Slide)view.Slide;
             presentation.Slides[slide.SlideIndex].Delete();
         }
     }
     catch (Exception)
     {
         // throw;
     }
 }
 public void settext(string title)
 {
     try
     {
         if (Globals.ThisAddIn.Application.ActiveWindow.Active == Office.MsoTriState.msoTrue)
         {
             PowerPoint.View         view         = Globals.ThisAddIn.Application.ActiveWindow.View;
             PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
             PowerPoint.Slide        slide        = (PowerPoint.Slide)view.Slide;
             slide.Shapes.Title.TextFrame.TextRange.Text = title;
         }
     }
     catch (Exception)
     {
         // throw;
     }
 }
示例#5
0
        public static void GoToSlide(PowerPoint.View view, string slideNumberString)
        {
            int slideNumber;

            if (Int32.TryParse(slideNumberString, out slideNumber))
            {
                try
                {
                    view.GotoSlide(slideNumber);
                }
                catch (Exception)
                {
                    System.Windows.Forms.MessageBox.Show(String.Format("Could not load slide number {0}.\nTry again.", slideNumber));
                }
            }
            else
            {
                System.Windows.Forms.MessageBox.Show("Could not parse number.\nTry again.");
            }
        }
        public void gotoSlide(int addcount)
        {
            try
            {
                if (Globals.ThisAddIn.Application.ActiveWindow.Active == Office.MsoTriState.msoTrue)
                {
                    PowerPoint.View         view         = Globals.ThisAddIn.Application.ActiveWindow.View;
                    PowerPoint.Presentation presentation = Globals.ThisAddIn.Application.ActivePresentation;
                    PowerPoint.Slide        slide        = (PowerPoint.Slide)view.Slide;
                    if (slide.SlideIndex + addcount > 0 && addcount <= presentation.Slides.Count)
                    {
                        view.GotoSlide(slide.SlideIndex + addcount);
                    }
                }
            }
            catch (Exception)
            {
                // throw;
            }

            try
            {
                if (Globals.ThisAddIn.Application.ActivePresentation.SlideShowWindow.Active == Office.MsoTriState.msoTrue)
                {
                    PowerPoint.SlideShowView view         = Globals.ThisAddIn.Application.ActivePresentation.SlideShowWindow.View;
                    PowerPoint.Presentation  presentation = Globals.ThisAddIn.Application.ActivePresentation;
                    PowerPoint.Slide         slide        = (PowerPoint.Slide)view.Slide;
                    if (slide.SlideIndex + addcount > 0 && addcount <= presentation.Slides.Count)
                    {
                        view.GotoSlide(slide.SlideIndex + addcount);
                    }
                }
            }
            catch (Exception)
            {
                // throw;
            }
        }
示例#7
0
        private void InsertItem(IFileItem item)
        {
            if (item == null)
            {
                return;
            }

            PPT.Application   app  = new PPT.Application();
            PPT.Presentations pres = app.Presentations;

            PPT.Presentation pptx   = pres.Open(item.File.FullPath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            PPT.Slides       slides = pptx.Slides;
            PPT.Slide        slide  = slides[item.Index];

            if (item.Type == ItemType.Slide)
            {
                slide.Copy();
            }
            else
            {
                PPT.Shapes shapes = slide.Shapes;
                PPT.Shape  shape  = shapes[1];

                shape.Copy();

                shapes.ReleaseCOM();
                shapes = null;
                shape.ReleaseCOM();
                shape = null;
            }

            PPT.Presentation dstpptx = app.ActivePresentation;

            PPT.DocumentWindow wnd  = app.ActiveWindow;
            PPT.View           view = wnd.View;

            //TODO: Check if there is no selection (selection between slides)
            PPT.Slides dstSlides = dstpptx.Slides;
            PPT.Slide  dstSlide  = null;

            dstSlide = view.Slide as PPT.Slide;
            int ix = dstSlide.SlideIndex + 1;

            if (item.Type == ItemType.Slide)
            {
                dstSlide.Copy();

                var r = dstSlides.Paste(); //TODO: dstSlides.Paste(ix) Hangs here
                var s = r[1];

                s.MoveTo(ix);

                s.ReleaseCOM();
                s = null;

                r.ReleaseCOM();
                r = null;
            }
            else
            {
                view.Paste();
            }

            dstSlide.ReleaseCOM();
            dstSlide = null;

            wnd.ReleaseCOM();
            wnd = null;

            view.ReleaseCOM();
            view = null;

            dstpptx.ReleaseCOM();
            dstpptx = null;


            slide.ReleaseCOM();
            slide = null;

            slides.ReleaseCOM();
            slides = null;

            pptx.Close();
            pptx.ReleaseCOM();
            pptx = null;

            pres.ReleaseCOM();
            pres = null;

            app.ReleaseCOM();
            app = null;

            dstSlides.ReleaseCOM();
            dstSlides = null;
        }