예제 #1
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText);

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #2
0
        public void SavePresentationsAs(IEnumerable <string> presentations, string exportFullFileName)
        {
            using (var powPointDestination = new PowerPoint.Application())
            {
                using (var powPointSource = new PowerPoint.Application())
                {
                    var destPresentation = powPointDestination.Presentations.Add(MsoTriState.msoTrue);

                    //The newly created presentation has to have at least one slide for the method to work properly
                    destPresentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                    foreach (var sourcePresentationPath in presentations)
                    {
                        var sourcePresentation = powPointSource.Presentations.Open(sourcePresentationPath, true);
                        this.CopySlidesTo(sourcePresentation, destPresentation);
                        this.SavePresentationAs(exportFullFileName, destPresentation);
                        sourcePresentation.Close();
                    }

                    //We need to delete the first empty slide added at the beginning
                    this.DeleteSlideAt(destPresentation, 1);

                    this.SavePresentationAs(exportFullFileName, destPresentation);

                    destPresentation.Close();

                    // close power point and dispose reference
                    powPointSource.Quit();
                    powPointDestination.Quit();
                }
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Presentation Fetch(string name)
        {
            //try to get the active PPT Instance
            this.application = PowerPoint.Application.GetActiveInstance();
            if (this.application == null)
            {
                //start PPT if ther is no active instance
                throw new Exception("Missing PowerPoint Application");
            }
            this.application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;
            Presentation presentation = null;

            if (name != null)
            {
                try
                {
                    presentation = new Presentation(this.application.Presentations[name]);
                }catch
                {
                    throw new Exception("Cannot find the PowerPoint presentations");
                }
            }
            else
            {
                presentation = new Presentation(this.application.ActivePresentation);
            }

            return(presentation);
        }
예제 #4
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start powerpoint and turn off msg boxes
            PowerPoint.Application powerApplication = new PowerPoint.Application();
            powerApplication.Visible = MsoTriState.msoTrue;

            // PowerPoint 2000 doesnt support DisplayAlerts, we check at runtime its available and set
            if (powerApplication.EntityIsAvailable("DisplayAlerts"))
            {
                powerApplication.DisplayAlerts = PpAlertLevel.ppAlertsNone;
            }

            // we register some events. note: the event trigger was called from power point, means an other Thread
            powerApplication.PresentationCloseEvent    += new NetOffice.PowerPointApi.Application_PresentationCloseEventHandler(powerApplication_PresentationCloseEvent);
            powerApplication.AfterNewPresentationEvent += new NetOffice.PowerPointApi.Application_AfterNewPresentationEventHandler(powerApplication_AfterNewPresentationEvent);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // close the document
            presentation.Close();

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();
        }
예제 #5
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #6
0
        public void RunExample()
        {
            // start powerpoint 
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with two new slides
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide1 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);
            PowerPoint.Slide slide2 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add shapes
            slide1.Shapes.AddShape(MsoAutoShapeType.msoShape4pointStar, 100, 100, 200, 200);
            slide2.Shapes.AddShape(MsoAutoShapeType.msoShapeDoubleWave, 200, 200, 200, 200);

            // change blend animation
            slide1.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverDown;
            slide1.SlideShowTransition.Speed = PpTransitionSpeed.ppTransitionSpeedFast;

            slide2.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverLeftDown;
            slide2.SlideShowTransition.Speed = PpTransitionSpeed.ppTransitionSpeedFast;

            // save the document 
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile = string.Format("{0}\\Example04{1}", _hostApplication.RootDirectory, fileExtension);
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Presentation Fetch(string name)
        {
            //try to get the active PPT Instance
            this.application = PowerPoint.Application.GetActiveInstance();
            if (this.application == null)
            {
                //start PPT if ther is no active instance
                throw new Exception("Missing PowerPoint Application");
            }
            this.application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;
            Presentation presentation = null;
            if (name != null)
            {
                try
                {
                    presentation = new Presentation(this.application.Presentations[name]);
                }catch
                {
                    throw new Exception("Cannot find the PowerPoint presentations");
                }
            }
            else
            {
                presentation = new Presentation(this.application.ActivePresentation);

            }

            return presentation;
        }
예제 #8
0
        public void RunExample()
        {
            // start powerpoint 
            PowerPoint.Application powerApplication = new PowerPoint.Application();
         
            // create a utils instance, not need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with two new slides
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide1 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);
            PowerPoint.Slide slide2 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add shapes
            slide1.Shapes.AddShape(MsoAutoShapeType.msoShape4pointStar, 100, 100, 200, 200);
            slide2.Shapes.AddShape(MsoAutoShapeType.msoShapeDoubleWave, 200, 200, 200, 200);

            // change blend animation
            slide1.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverDown;
            slide1.SlideShowTransition.Speed = PpTransitionSpeed.ppTransitionSpeedFast;

            slide2.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverLeftDown;
            slide2.SlideShowTransition.Speed = PpTransitionSpeed.ppTransitionSpeedFast;

            // save the document 
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example04", PowerPoint.Tools.DocumentFormat.Normal); 
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #9
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a chart
            slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse);

            // save the document
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile  = string.Format("{0}\\Example05{1}", _hostApplication.RootDirectory, fileExtension);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #10
0
 static void GetActivePowerPointInstance()
 {
     PowerPoint.Application application = null;
     try
     {
         NetOffice.Settings.Default.UseExceptionMessage = NetOffice.ExceptionMessageHandling.CopyInnerExceptionMessageToTopLevelException;
         Console.WriteLine("NetOffice Concept Test - PowerPoint.Application.GetActiveInstance(){0}", Environment.NewLine);
         application = PowerPoint.Application.GetActiveInstance(false);
         if (null != application)
         {
             Console.WriteLine("Current PowerPoint Application Visibility: {0}", application.Visible);
         }
         else
         {
             Console.WriteLine("No PowerPoint Application running.");
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine("An error has occured. {0}", exception.Message);
     }
     finally
     {
         if (null != application)
         {
             application.Dispose();
             application = null;
         }
     }
 }
예제 #11
0
        public static StringBuilder Start(string filePath)
        {
            StringBuilder stringBuilder = new StringBuilder();

            PowerPoint.Application   powerApplication = new PowerPoint.Application();
            PowerPoint.Presentations pptPresentations = powerApplication.Presentations;

            PowerPoint.Presentation pptPresentation = pptPresentations.Open(filePath,
                                                                            MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

            PowerPoint.Slides pptSlides = pptPresentation.Slides;

            if (pptSlides != null)
            {
                //var slidesCount = pptSlides.Count;

                foreach (PowerPoint.Slide slide in pptSlides)
                {
                    foreach (PowerPoint.Shape shape in slide.Shapes)
                    {
                        if (shape.HasTextFrame == MsoTriState.msoTrue && shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            PowerPoint.TextRange range = shape.TextFrame.TextRange;
                            if (range != null && range.Length > 0)
                            {
                                stringBuilder.Append(" " + range.Text);
                            }
                        }
                    }
                }
            }
            return(stringBuilder);
        }
예제 #12
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // create a utils instance, no need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a chart
            slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse);

            // save the document
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example05", DocumentFormat.Normal);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show end dialog
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #13
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add a chart. MSGraph.Chart is may not installed
                slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse); 

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #14
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start powerpoint and turn off msg boxes
            PowerPoint.Application powerApplication = new PowerPoint.Application();
	        powerApplication.Visible = MsoTriState.msoTrue;

            // PowerPoint 2000 doesnt support DisplayAlerts, we check at runtime its available and set
            if(powerApplication.EntityIsAvailable("DisplayAlerts"))
                powerApplication.DisplayAlerts = PpAlertLevel.ppAlertsNone;

            // we register some events. note: the event trigger was called from power point, means an other Thread
            powerApplication.PresentationCloseEvent += new NetOffice.PowerPointApi.Application_PresentationCloseEventHandler(powerApplication_PresentationCloseEvent);
            powerApplication.AfterNewPresentationEvent += new NetOffice.PowerPointApi.Application_AfterNewPresentationEventHandler(powerApplication_AfterNewPresentationEvent);
             
            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // close the document
            presentation.Close();

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();
        }
예제 #15
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with two new slides
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide1       = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);
            PowerPoint.Slide        slide2       = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add shapes
            slide1.Shapes.AddShape(MsoAutoShapeType.msoShape4pointStar, 100, 100, 200, 200);
            slide2.Shapes.AddShape(MsoAutoShapeType.msoShapeDoubleWave, 200, 200, 200, 200);

            // change blend animation
            slide1.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverDown;
            slide1.SlideShowTransition.Speed       = PpTransitionSpeed.ppTransitionSpeedFast;

            slide2.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverLeftDown;
            slide2.SlideShowTransition.Speed       = PpTransitionSpeed.ppTransitionSpeedFast;

            // save the document
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile  = string.Format("{0}\\Example04{1}", _hostApplication.RootDirectory, fileExtension);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #16
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add a chart. MSGraph.Chart is may not installed
                slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #17
0
        public void RunExample()
        {
            // start powerpoint 
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // create a utils instance, not need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a chart
            slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse);

            // save the document
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example05", PowerPoint.Tools.DocumentFormat.Normal); 
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #18
0
        public void RunExample()
        {
            // start powerpoint 
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a label
            PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
            label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

            // add a line
            slide.Shapes.AddLine(10, 80, 700, 80);

            // add a wordart
            slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                           MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

            // add a star
            slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

            // save the document 
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile = string.Format("{0}\\Example02{1}", _hostApplication.RootDirectory, fileExtension);
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #19
0
 public PPTViewer()
 {
     InitializeComponent();
     ppt            = new PowerPoint.Application();
     ppt.Visible    = Office.Enums.MsoTriState.msoTrue;
     timer          = new System.Timers.Timer(200);
     timer.Elapsed += (sender, e) => refresh();
 }
예제 #20
0
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _powerApplication = new PowerPoint.Application(null, Application);
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
         MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #21
0
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     try
     {
         _powerApplication = new PowerPoint.Application(null, Application);
     }
     catch (Exception exception)
     {
         string message = string.Format("An error occured.{0}{0}{1}", Environment.NewLine, exception.Message);
         MessageBox.Show(message, _progId, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
        private static void SelectSlideMasterLayoutOfActiveSlide(PowerPoint.Application app)
        {
            var activeWindow = app.ActiveWindow;
            var slideObj     = activeWindow.View.Slide;

            if (slideObj.GetType() == typeof(PowerPoint.Slide))
            {
                var slide = (PowerPoint.Slide)slideObj;
                activeWindow.ViewType = PpViewType.ppViewSlideMaster;     //PpViewType.ppViewMasterThumbnails doesn't work for me for some reason
                slide.CustomLayout.Select();
            }
        }
예제 #23
0
        public void RunExample()
        {
            bool   isFailed     = false;
            string documentFile = null;

            PowerPoint.Application powerApplication = null;
            try
            {
                // start powerpoint
                powerApplication = COMObject.Create <PowerPoint.Application>();

                // create a utils instance, no need for but helpful to keep the lines of code low
                CommonUtils utils = new CommonUtils(powerApplication);

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add new module and insert macro. the option "Trust access to Visual Basic Project" must be set
                VB.CodeModule module = presentation.VBProject.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule).CodeModule;
                string        macro  = string.Format("Sub NetOfficeTestMacro()\r\n   {0}\r\nEnd Sub", "MsgBox \"Thanks for click!\"");
                module.InsertLines(1, macro);

                // add button and connect with macro
                PowerPoint.Shape button = slide.Shapes.AddShape(MsoAutoShapeType.msoShapeActionButtonForwardorNext, 100, 100, 200, 200);
                button.ActionSettings[PpMouseActivation.ppMouseClick].AnimateAction = MsoTriState.msoTrue;
                button.ActionSettings[PpMouseActivation.ppMouseClick].Action        = PpActionType.ppActionRunMacro;
                button.ActionSettings[PpMouseActivation.ppMouseClick].Run           = "NetOfficeTestMacro";

                // save the document
                documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example03", DocumentFormat.Macros);
                presentation.SaveAs(documentFile);
            }
            catch (System.Runtime.InteropServices.COMException throwedException)
            {
                isFailed = true;
                HostApplication.ShowErrorDialog("VBA Error", throwedException);
            }
            finally
            {
                // close power point and dispose reference
                if (powerApplication != null)
                {
                    powerApplication.Quit();
                    powerApplication.Dispose();
                }

                if ((null != documentFile) && (!isFailed))
                {
                    HostApplication.ShowFinishDialog(null, documentFile);
                }
            }
        }
예제 #24
0
        public PowerPointApplication(object application, object ctpFactoryInst, Type contentType)
            : base(application, ctpFactoryInst, contentType)
        {
            this.application = application as NetOffice.PowerPointApi.Application;

            this.application.AfterNewPresentationEvent   += OnAfterNewElement;
            this.application.AfterPresentationOpenEvent  += OnAfterOpenElement;
            this.application.PresentationSaveEvent       += OnAfterSaveElement;;
            this.application.PresentationCloseFinalEvent += OnAfterCloseEvent;

            this.application.OnDispose += OnApplicationDispose;
        }
예제 #25
0
        /// <summary>
        /// returns the valid file extension for the instance. for example ".ppt" or ".pptx"
        /// </summary>
        /// <param name="application">the instance</param>
        /// <returns>the extension</returns>
        private static string GetDefaultExtension(PowerPoint.Application application)
        {
            double Version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);

            if (Version >= 12.00)
            {
                return(".pptx");
            }
            else
            {
                return(".ppt");
            }
        }
예제 #26
0
        public void RunExample()
        {
            bool isFailed = false;
            string documentFile = null;
            PowerPoint.Application powerApplication = null;
            try
            {
                // start powerpoint
                powerApplication = new PowerPoint.Application();

                // create a utils instance, not need for but helpful to keep the lines of code low
                CommonUtils utils = new CommonUtils(powerApplication);

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add new module and insert macro. the option "Trust access to Visual Basic Project" must be set
                VB.CodeModule module = presentation.VBProject.VBComponents.Add(vbext_ComponentType.vbext_ct_StdModule).CodeModule;
                string macro = string.Format("Sub NetOfficeTestMacro()\r\n   {0}\r\nEnd Sub", "MsgBox \"Thanks for click!\"");
                module.InsertLines(1, macro);

                // add button and connect with macro
                PowerPoint.Shape button = slide.Shapes.AddShape(MsoAutoShapeType.msoShapeActionButtonForwardorNext, 100, 100, 200, 200);
                button.ActionSettings[PpMouseActivation.ppMouseClick].AnimateAction = MsoTriState.msoTrue;
                button.ActionSettings[PpMouseActivation.ppMouseClick].Action = PpActionType.ppActionRunMacro;
                button.ActionSettings[PpMouseActivation.ppMouseClick].Run = "NetOfficeTestMacro";
               
                // save the document 
                documentFile =  utils.File.Combine(HostApplication.RootDirectory, "Example03", PowerPoint.Tools.DocumentFormat.Macros);
                presentation.SaveAs(documentFile);
            }
            catch (System.Runtime.InteropServices.COMException throwedException)
            {
                isFailed = true;
                HostApplication.ShowErrorDialog("VBA Error", throwedException);
            }
            finally
            {
                // close power point and dispose reference
                if (powerApplication != null)
                {
                    powerApplication.Quit();
                    powerApplication.Dispose();
                }

                if ((null != documentFile) && (!isFailed))
                    HostApplication.ShowFinishDialog(null, documentFile);
            }
        }
예제 #27
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application         = new PowerPoint.Application();
                application.Visible = MsoTriState.msoTrue;

                // PowerPoint 2000 doesnt support DisplayAlerts, we check at runtime its available and set
                if (application.EntityIsAvailable("DisplayAlerts"))
                {
                    application.DisplayAlerts = PpAlertLevel.ppAlertsNone;
                }

                application.PresentationCloseEvent    += new NetOffice.PowerPointApi.Application_PresentationCloseEventHandler(powerApplication_PresentationCloseEvent);
                application.AfterNewPresentationEvent += new NetOffice.PowerPointApi.Application_AfterNewPresentationEventHandler(powerApplication_AfterNewPresentationEvent);

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                System.Threading.Thread.Sleep(2000);

                // close the document
                presentation.Close();

                if (_afterNewPresentation && _presentationClose)
                {
                    return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
                }
                else
                {
                    return(new TestResult(false, DateTime.Now.Subtract(startTime), String.Format("AfterNewPresentation:{0} , PresentationClose:{1}", _afterNewPresentation, _presentationClose), null, ""));
                }
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #28
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Presentation Open(string name)
        {
            //try to get the active PPT Instance
            this.application = PowerPoint.Application.GetActiveInstance();
            if (this.application == null)
            {
                //start PPT if ther is no active instance
                this.application      = new PowerPoint.Application();
                this.closeApplication = true;
            }

            this.application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;
            name = name.Replace('/', '\\');
            return(new Presentation(this.application.Presentations.Open(name)));
        }
예제 #29
0
        public Form1()
        {
            InitializeComponent();
            Point.Application application = new NetOffice.PowerPointApi.Application();
            application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;

            NetOffice.PowerPointApi.Tools.Utils.CommonUtils utils = new Point.Tools.Utils.CommonUtils(application);
            string hwnd1 = utils.Application.HWND.ToString();
            string hwnd2 = application.HWND.ToString();
            Console.WriteLine(hwnd1);
            Console.WriteLine(hwnd2);

            //application.Quit();
            //application.Dispose();
        }
예제 #30
0
        public Form1()
        {
            InitializeComponent();
            Point.Application application = new NetOffice.PowerPointApi.Application();
            application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;

            NetOffice.PowerPointApi.Tools.Utils.CommonUtils utils = new Point.Tools.Utils.CommonUtils(application);
            string hwnd1 = utils.Application.HWND.ToString();
            string hwnd2 = application.HWND.ToString();

            Console.WriteLine(hwnd1);
            Console.WriteLine(hwnd2);

            //application.Quit();
            //application.Dispose();
        }
예제 #31
0
        /// <summary>
        /// Creates an instance of the class
        /// </summary>
        /// <param name="application"></param>
        /// <exception cref="ArgumentNullException">given application is null</exception>
        /// <exception cref="ObjectDisposedException">given application is already disposed</exception>
        public FileUtils(PowerPoint.Application application)
        {
            if (null == application)
            {
                throw new ArgumentNullException("application");
            }
            if (application.IsDisposed)
            {
                throw new ObjectDisposedException("application");
            }

            double?version = NetOffice.OfficeApi.Tools.Contribution.CommonUtils.TryGetApplicationVersion(application);

            if (null != version && version >= 12.00)
            {
                _applicationIs2007OrHigher = true;
            }
        }
예제 #32
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new PowerPoint.Application();
                application.Visible = MsoTriState.msoTrue;

                // PowerPoint 2000 doesnt support DisplayAlerts, we check at runtime its available and set
                if (application.EntityIsAvailable("DisplayAlerts"))
                    application.DisplayAlerts = PpAlertLevel.ppAlertsNone;

                application.PresentationCloseEvent += new NetOffice.PowerPointApi.Application_PresentationCloseEventHandler(powerApplication_PresentationCloseEvent);
                application.AfterNewPresentationEvent += new NetOffice.PowerPointApi.Application_AfterNewPresentationEventHandler(powerApplication_AfterNewPresentationEvent);

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                System.Threading.Thread.Sleep(2000);

                // close the document
                presentation.Close();

                if(_afterNewPresentation && _presentationClose)
                    return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
                else
                    return new TestResult(false, DateTime.Now.Subtract(startTime), String.Format("AfterNewPresentation:{0} , PresentationClose:{1}", _afterNewPresentation, _presentationClose), null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #33
0
        private static void TestPowerPoint()
        {
            Console.WriteLine("Test PowerPoint Application Utils");

            PowerPoint.Application application = new PowerPoint.Application();
            application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;
            application.Presentations.Add();

            PowerPoint.Tools.Utils.CommonUtils utils = new PowerPoint.Tools.Utils.CommonUtils(application);
            int hwnd = utils.Application.HWND;

            application.Quit();
            application.Dispose();

            if (0 == hwnd)
            {
                throw new Exception("Cant resolve powerpoint hwnd");
            }
        }
예제 #34
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application = COMObject.Create <PowerPoint.Application>(COMObjectCreateOptions.CreateNewCore);

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add a label
                PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
                label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

                // add a line
                slide.Shapes.AddLine(10, 80, 700, 80);

                // add a wordart
                slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                           MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

                // add a star
                slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #35
0
        /// <summary>
        /// Get the active PowerPoint slide show window object
        ///
        /// If there are multiple active slide shows, only the first slide show window object will be returned
        /// </summary>
        /// <returns>SlideShowWindow, or null if none</returns>
        private static SlideShowWindow GetActiveSlideShowWindow()
        {
            try
            {
                PPt.Application pptApplication = PPt.Application.GetActiveInstance();

                if (pptApplication == null)
                {
                    return(null);
                }

                SlideShowWindow w = (SlideShowWindow)pptApplication.SlideShowWindows.FirstOrDefault();

                return(w);
            }
            catch (Exception)
            {
                return(null);
            }
        }
예제 #36
0
 // Dispose(bool disposing) executes in two distinct scenarios.
 // If disposing equals true, the method has been called directly
 // or indirectly by a user's code. Managed and unmanaged resources
 // can be disposed.
 // If disposing equals false, the method has been called by the
 // runtime from inside the finalizer and you should not reference
 // other objects. Only unmanaged resources can be disposed.
 protected virtual void Dispose(bool disposing)
 {
     // Check to see if Dispose has already been called.
     if (!this.disposed)
     {
         // If disposing equals true, dispose all managed
         // and unmanaged resources.
         if (disposing)
         {
             if (this.closeApplication)
             {
                 this.application.Quit();
             }
             this.application.Dispose();
             this.application = null;
         }
         // Note disposing has been done.
         this.disposed = true;
     }
 }
예제 #37
0
        // NOTE: Wrap most things in try-catch, as the Office COM API can throw exceptions rather unexpectedly
        bool IClickerTarget.IsActive()
        {
            try
            {
                PPt.Application pptApplication = PPt.Application.GetActiveInstance();

                if (pptApplication == null)
                {
                    return(false);
                }

                // Check if there is an active slide show
                return(pptApplication.SlideShowWindows.Count > 0);
            }
            catch (Exception)
            {
            }

            return(false);
        }
예제 #38
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add a label
                PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
                label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

                // add a line
                slide.Shapes.AddLine(10, 80, 700, 80);

                // add a wordart
                slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                               MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

                // add a star
                slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #39
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText);
            
            // save the document 
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile = string.Format("{0}\\Example01{1}", _hostApplication.RootDirectory, fileExtension);
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #40
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;

            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with two new slides
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide        slide1       = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);
                PowerPoint.Slide        slide2       = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add shapes
                slide1.Shapes.AddShape(MsoAutoShapeType.msoShape4pointStar, 100, 100, 200, 200);
                slide2.Shapes.AddShape(MsoAutoShapeType.msoShapeDoubleWave, 200, 200, 200, 200);

                // change blend animation
                slide1.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverDown;
                slide1.SlideShowTransition.Speed       = PpTransitionSpeed.ppTransitionSpeedFast;

                slide2.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverLeftDown;
                slide2.SlideShowTransition.Speed       = PpTransitionSpeed.ppTransitionSpeedFast;

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #41
0
 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.msoTrue);
         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();
     }
 }
예제 #42
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText);

            // save the document
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile  = string.Format("{0}\\Example01{1}", _hostApplication.RootDirectory, fileExtension);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #43
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                application = new PowerPoint.Application();

                // add a new presentation with two new slides
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide slide1 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);
                PowerPoint.Slide slide2 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add shapes
                slide1.Shapes.AddShape(MsoAutoShapeType.msoShape4pointStar, 100, 100, 200, 200);
                slide2.Shapes.AddShape(MsoAutoShapeType.msoShapeDoubleWave, 200, 200, 200, 200);

                // change blend animation
                slide1.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverDown;
                slide1.SlideShowTransition.Speed = PpTransitionSpeed.ppTransitionSpeedFast;

                slide2.SlideShowTransition.EntryEffect = PpEntryEffect.ppEffectCoverLeftDown;
                slide2.SlideShowTransition.Speed = PpTransitionSpeed.ppTransitionSpeedFast;

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #44
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // create a utils instance, no need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a label
            PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
            label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

            // add a line
            slide.Shapes.AddLine(10, 80, 700, 80);

            // add a wordart
            slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                       MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

            // add a star
            slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

            // save the document
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example02", DocumentFormat.Normal);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show end dialog
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #45
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // create a utils instance, not need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText);
            
            // save the document 
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example01", PowerPoint.Tools.DocumentFormat.Normal);
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #46
0
        public void RunExample()
        {
            // start powerpoint 
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // create a utils instance, not need for but helpful to keep the lines of code low
            CommonUtils utils = new CommonUtils(powerApplication);

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a label
            PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
            label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

            // add a line
            slide.Shapes.AddLine(10, 80, 700, 80);

            // add a wordart
            slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                           MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

            // add a star
            slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

            // save the document 
            string documentFile = utils.File.Combine(HostApplication.RootDirectory, "Example02", PowerPoint.Tools.DocumentFormat.Normal); 
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            HostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #47
0
        public void RunExample()
        {
            // start powerpoint 
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a chart
            slide.Shapes.AddOLEObject(120, 111, 480, 320, "MSGraph.Chart", "", MsoTriState.msoFalse, "", 0, "", MsoTriState.msoFalse);

            // save the document
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile = string.Format("{0}\\Example05{1}", _hostApplication.RootDirectory, fileExtension);
            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #48
0
        public void RunExample()
        {
            // start powerpoint
            PowerPoint.Application powerApplication = new PowerPoint.Application();

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide        slide        = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a label
            PowerPoint.Shape label = slide.Shapes.AddLabel(MsoTextOrientation.msoTextOrientationHorizontal, 10, 10, 600, 20);
            label.TextFrame.TextRange.Text = "This slide and created Shapes are created by NetOffice example.";

            // add a line
            slide.Shapes.AddLine(10, 80, 700, 80);

            // add a wordart
            slide.Shapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect9, "This a WordArt", "Arial", 20,
                                       MsoTriState.msoTrue, MsoTriState.msoFalse, 10, 150);

            // add a star
            slide.Shapes.AddShape(MsoAutoShapeType.msoShape24pointStar, 200, 200, 250, 250);

            // save the document
            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile  = string.Format("{0}\\Example02{1}", _hostApplication.RootDirectory, fileExtension);

            presentation.SaveAs(documentFile);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            // show dialog for the user(you!)
            _hostApplication.ShowFinishDialog(null, documentFile);
        }
예제 #49
0
 private void CreateOfficeApplication()
 {
     switch (_officeApp)
     {
         case "Excel":
             _excelApplication = new Excel.Application("Excel.Application");
             break;
         case "Word":
             _wordApplication = new Word.Application("Word.Application");
             break;
         case "Outlook":
             _outlookApplication = new Outlook.Application("Outlook.Application");
             break;
         case "Power Point":
             _powerpointApplication = new PowerPoint.Application("PowerPoint.Application");
             break;
         case "Access":
             _accessApplication = new Access.Application("Access.Application");
             break;
         case "Project":
             _projectApplication = new Project.Application("MSProject.Application");
             break;
         case "Visio":
             _visioApplication = new Visio.Application("Visio.Application");
             break;
         default:
             throw new ArgumentOutOfRangeException("officeApp");
     }
 }
예제 #50
0
        private static void TestPowerPoint()
        {
            Console.WriteLine("Test PowerPoint Application Utils");

            PowerPoint.Application application = new PowerPoint.Application();
            application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;
            application.Presentations.Add();

            PowerPoint.Tools.Utils.CommonUtils utils = new PowerPoint.Tools.Utils.CommonUtils(application);
            int hwnd = utils.Application.HWND;

            application.Quit();
            application.Dispose();

            if (0 == hwnd)
                throw new Exception("Cant resolve powerpoint hwnd");
        }
 void Extensibility.IDTExtensibility2.OnConnection(object Application, Extensibility.ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
 {
     //thisPowerPoint = (POWERPNT.Application) Application;
     thisPowerPoint  = new POWERPNT.Application(null, Application);
 }
예제 #52
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public Presentation Open(string name)
        {
            //try to get the active PPT Instance
            this.application = PowerPoint.Application.GetActiveInstance();
            if (this.application == null)
            {
                //start PPT if ther is no active instance
                this.application = new PowerPoint.Application();
                this.closeApplication = true;
            }

            this.application.Visible = NetOffice.OfficeApi.Enums.MsoTriState.msoTrue;
            name = name.Replace('/', '\\');
            return new Presentation(this.application.Presentations.Open(name));
        }
예제 #53
0
        // Dispose(bool disposing) executes in two distinct scenarios.
        // If disposing equals true, the method has been called directly
        // or indirectly by a user's code. Managed and unmanaged resources
        // can be disposed.
        // If disposing equals false, the method has been called by the
        // runtime from inside the finalizer and you should not reference
        // other objects. Only unmanaged resources can be disposed.
        protected virtual void Dispose(bool disposing)
        {
            // Check to see if Dispose has already been called.
            if (!this.disposed)
            {
                // If disposing equals true, dispose all managed
                // and unmanaged resources.
                if (disposing)
                {
                    if (this.closeApplication)
                    {

                        this.application.Quit();
                    }
                    this.application.Dispose();
                    this.application = null;
                }
                // Note disposing has been done.
                this.disposed = true;

            }
        }
 public PowerPointApi(PPt.Application thisPPtInstance)
 {
     pptApplication = thisPPtInstance;
 }
예제 #55
0
파일: Program.cs 프로젝트: imperugo/Spike
        private static string GetDefaultExtension(Application application)
        {
            double version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);

            return version >= 12.00 ? ".pptx" : ".ppt";
        }
예제 #56
0
파일: Program.cs 프로젝트: imperugo/Spike
        private static void Main(string[] args)
        {
            var powerApplication = new Application();
            var presentation = powerApplication.Presentations.Add(MsoTriState.msoTrue);

            var slide1 = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            //Access the first slide of presentation
            slide1 = presentation.Slides[1];

            //Select firs slide and set its layout
            slide1.Select();
            slide1.Layout = PpSlideLayout.ppLayoutBlank;

            //Add a default chart in slide
            slide1.Shapes.AddChart(Microsoft.Office.Core.XlChartType.xl3DColumn, 20F, 30F, 400F, 300F);

            //Access the added chart
            Chart ppChart = slide1.Shapes[1].Chart;

            //Access the chart data
            ChartData chartData = ppChart.ChartData;

            //Create instance to Excel workbook to work with chart data
            Workbook dataWorkbook = (Workbook)chartData.Workbook;

            //Accessing the data worksheet for chart
            Worksheet dataSheet = (Worksheet)dataWorkbook.Worksheets[1];

            //Setting the range of chart
            Range tRange = dataSheet.Cells.get_Range("A1", "B5");

            //Applying the set range on chart data table
            ListObject tbl1 = dataSheet.ListObjects["Table1"];
            tbl1.Resize(tRange);

            // Setting values for categories and respective series data

            ((Range)(dataSheet.Cells.get_Range("A2"))).FormulaR1C1 = "Bikes";
            ((Range)(dataSheet.Cells.get_Range("A3"))).FormulaR1C1 = "Accessories";
            ((Range)(dataSheet.Cells.get_Range("A4"))).FormulaR1C1 = "Repairs";
            ((Range)(dataSheet.Cells.get_Range("A5"))).FormulaR1C1 = "Clothing";
            ((Range)(dataSheet.Cells.get_Range("B2"))).FormulaR1C1 = "1000";
            ((Range)(dataSheet.Cells.get_Range("B3"))).FormulaR1C1 = "2500";
            ((Range)(dataSheet.Cells.get_Range("B4"))).FormulaR1C1 = "4000";
            ((Range)(dataSheet.Cells.get_Range("B5"))).FormulaR1C1 = "3000";

            //Setting chart title
            ppChart.ChartTitle.Font.Italic = true;
            ppChart.ChartTitle.Text = "2007 Sales";
            ppChart.ChartTitle.Font.Size = 18;
            ppChart.ChartTitle.Font.Color = Color.Black.ToArgb();
            ppChart.ChartTitle.Format.Line.Visible = MsoTriState.msoTrue;
            ppChart.ChartTitle.Format.Line.ForeColor.RGB = Color.Black.ToArgb();

            //Accessing Chart value axis
            Axis valaxis = (Axis)ppChart.Axes(XlAxisType.xlValue, XlAxisGroup.xlPrimary);

            //Setting values axis units
            valaxis.MajorUnit = 2000.0F;
            valaxis.MinorUnit = 1000.0F;
            valaxis.MinimumScale = 0.0F;
            valaxis.MaximumScale = 4000.0F;

            //Accessing Chart Depth axis
            Axis Depthaxis = (Axis)ppChart.Axes(XlAxisType.xlSeriesAxis, XlAxisGroup.xlPrimary);
            Depthaxis.Delete();

            //Setting chart rotation
            ppChart.Rotation = 20; //Y-Value
            ppChart.Elevation = 15; //X-Value
            ppChart.RightAngleAxes = false;

            string fileExtension = GetDefaultExtension(powerApplication);
            string documentFile = $"{AppDomain.CurrentDomain.BaseDirectory}\\Example04{fileExtension}";

            presentation.SaveAs(documentFile,
                        PpSaveAsFileType.ppSaveAsDefault,
                        MsoTriState.msoTrue);

            // close power point and dispose reference
            powerApplication.Quit();
            powerApplication.Dispose();

            Console.WriteLine("Fatto...");
            Console.ReadLine();
        }
예제 #57
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {        
            // start powerpoint
            _powerApplication = new PowerPoint.Application();

            Office.CommandBar commandBar = null;
            Office.CommandBarButton commandBarBtn = null;

            // add a new presentation with one new slide
            PowerPoint.Presentation presentation = _powerApplication.Presentations.Add(MsoTriState.msoTrue);
            PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

            // add a commandbar popup
            Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)_powerApplication.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarPopup.Caption = "commandBarPopup";

            #region few words, how to access the picture
            /*
             you can see we use an own icon via .PasteFace()
             is not possible from outside process boundaries to use the PictureProperty directly
             the reason for is IPictureDisp: http://support.microsoft.com/kb/286460/de
             its not important is early or late binding or managed or unmanaged, the behaviour is always the same
             For example, a COMAddin running as InProcServer and can access the Picture Property
            */
            #endregion
            
            #region CommandBarButton

            // add a button to the popup
            commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            Clipboard.SetDataObject(HostApplication.DisplayIcon.ToBitmap());
            commandBarBtn.PasteFace();
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            #endregion

            #region Create a new toolbar

            // add a new toolbar
            commandBar = _powerApplication.CommandBars.Add("MyCommandBar", MsoBarPosition.msoBarTop, false, true);
            commandBar.Visible = true;

            // add a button to the toolbar
            commandBarBtn = (Office.CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            commandBarBtn.FaceId = 3;
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            // add a dropdown box to the toolbar
            commandBarPopup = (Office.CommandBarPopup)commandBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarPopup.Caption = "commandBarPopup";

            // add a button to the popup, we use an own icon for the button
            commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            Clipboard.SetDataObject(HostApplication.DisplayIcon.ToBitmap());
            commandBarBtn.PasteFace();
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            #endregion

            #region Create a new ContextMenu

            // add a commandbar popup
            commandBarPopup = (Office.CommandBarPopup)_powerApplication.CommandBars["Frames"].Controls.Add(
                                                            MsoControlType.msoControlPopup, Missing.Value, Missing.Value, Missing.Value, true);
            commandBarPopup.Caption = "commandBarPopup";

            // add a button to the popup
            commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true);
            commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
            commandBarBtn.Caption = "commandBarButton";
            commandBarBtn.FaceId = 9;
            commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

            #endregion

            // make visible & set buttons
            _powerApplication.Visible = MsoTriState.msoTrue;
            buttonStartExample.Enabled = false;
            buttonQuitExample.Enabled = true;             
        }
예제 #58
0
        public TestResult DoTest()
        {
            PowerPoint.Application application = null;
            DateTime startTime = DateTime.Now;
            try
            {
                Bitmap iconBitmap = new Bitmap(System.Reflection.Assembly.GetAssembly(this.GetType()).GetManifestResourceStream("PowerPointTestsCSharp.Test06.bmp"));
                application = new PowerPoint.Application();

                Office.CommandBar commandBar;
                Office.CommandBarButton commandBarBtn;

                // add a new presentation with one new slide
                PowerPoint.Presentation presentation = application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.Slide slide = presentation.Slides.Add(1, PpSlideLayout.ppLayoutBlank);

                // add a commandbar popup
                Office.CommandBarPopup commandBarPopup = (Office.CommandBarPopup)application.CommandBars["Menu Bar"].Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarPopup.Caption = "commandBarPopup";

                #region CommandBarButton

                // add a button to the popup
                commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                Clipboard.SetDataObject(iconBitmap);
                commandBarBtn.PasteFace();
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion

                #region Create a new toolbar

                // add a new toolbar
                commandBar = application.CommandBars.Add("MyCommandBar", MsoBarPosition.msoBarTop, false, true);
                commandBar.Visible = true;

                // add a button to the toolbar
                commandBarBtn = (Office.CommandBarButton)commandBar.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                commandBarBtn.FaceId = 3;
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                // add a dropdown box to the toolbar
                commandBarPopup = (Office.CommandBarPopup)commandBar.Controls.Add(MsoControlType.msoControlPopup, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarPopup.Caption = "commandBarPopup";

                // add a button to the popup, we use an own icon for the button
                commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, System.Type.Missing, System.Type.Missing, System.Type.Missing, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                Clipboard.SetDataObject(iconBitmap);
                commandBarBtn.PasteFace();
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion

                #region Create a new ContextMenu

                // add a commandbar popup
                commandBarPopup = (Office.CommandBarPopup)application.CommandBars["Frames"].Controls.Add(
                                                                MsoControlType.msoControlPopup, Missing.Value, Missing.Value, Missing.Value, true);
                commandBarPopup.Caption = "commandBarPopup";

                // add a button to the popup
                commandBarBtn = (Office.CommandBarButton)commandBarPopup.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true);
                commandBarBtn.Style = MsoButtonStyle.msoButtonIconAndCaption;
                commandBarBtn.Caption = "commandBarButton";
                commandBarBtn.FaceId = 9;
                commandBarBtn.ClickEvent += new Office.CommandBarButton_ClickEventHandler(commandBarBtn_Click);

                #endregion

                return new TestResult(true, DateTime.Now.Subtract(startTime), "", null, "");
            }
            catch (Exception exception)
            {
                return new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "");
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }