Пример #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
        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);
        }
Пример #4
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();
                }
            }
        }
Пример #5
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);
        }
Пример #6
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();
                }
            }
        }
Пример #7
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);
        }
Пример #8
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();
        }
Пример #9
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();
                }
            }
        }
Пример #10
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);
        }
Пример #11
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();
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
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);
        }
Пример #15
0
        private void buttonQuitExample_Click(object sender, EventArgs e)
        {
            _powerApplication.Quit();
            _powerApplication.Dispose();

            buttonStartExample.Enabled = true;
            buttonQuitExample.Enabled  = false;
        }
Пример #16
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);
                }
            }
        }
Пример #17
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();
                }
            }
        }
Пример #18
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);
            }
        }
Пример #19
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();
                }
            }
        }
Пример #20
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");
            }
        }
Пример #21
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();
                }
            }
        }
Пример #22
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();
                }
            }
        }
Пример #23
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);
        }
Пример #24
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();
                }
            }
        }
Пример #25
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();
     }
 }
Пример #26
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);
        }
Пример #27
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();
                }
            }
        }
Пример #28
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);
        }
Пример #29
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);
        }
Пример #30
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);
        }
Пример #31
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);
        }
Пример #32
0
        public void Quit()
        {
            switch (_officeApp)
            {
            case "Excel":
                _excelApplication.Quit();
                break;

            case "Word":
                _wordApplication.Quit();
                break;

            case "Outlook":
                _outlookApplication.Quit();
                break;

            case "Power Point":
                _powerpointApplication.Quit();
                break;

            case "Access":
                _accessApplication.Quit();
                break;

            case "Project":
                _projectApplication.Quit();
                break;

            case "Visio":
                _visioApplication.Quit();
                break;

            default:
                throw new ArgumentOutOfRangeException("officeApp");
            }
        }
Пример #33
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);
            presentation.Slides.Add(1, PpSlideLayout.ppLayoutClipArtAndVerticalText);

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

            presentation.SaveAs(documentFile);

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

            // show end dialog
            HostApplication.ShowFinishDialog(null, documentFile);
        }
Пример #34
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);
        }
Пример #35
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 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", DocumentFormat.Normal);

            presentation.SaveAs(documentFile);

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

            // show end dialog
            HostApplication.ShowFinishDialog(null, documentFile);
        }
Пример #36
0
        private void doWork2()
        {
            PowerPoint.Presentation presentation          = null;
            PowerPoint.Application  applicationPowerPoint = null;
            Excel.Workbook          book             = null;
            Excel.Application       applicationExcel = null;

            try
            {
                Dictionary <String, Excel.Shape> excelShapesDictionary = new Dictionary <string, Excel.Shape>();

                Log.Information("Opening Excel Applicaiton");
                applicationExcel = new Excel.Application();
                applicationExcel.DisplayAlerts = false;

                String xlsx          = "D:\\Input\\Input.xlsx";
                String output_folder = "D:\\Output";
                String pptxSingle    = "D:\\Input\\input.pptx";

                Log.Information("Opening Excel File {0}", xlsx);
                book = applicationExcel.Workbooks.Open(xlsx, true, true);

                Excel.Worksheet         worksheet         = (Excel.Worksheet)book.Worksheets[1];
                int                     index             = 3;
                List <PresentationItem> presentationItems = new List <PresentationItem>();
                do
                {
                    String s = worksheet.Range("A" + index).Value2.ToString();
                    Log.Information(worksheet.Name + " " + s);

                    PresentationItem presentationItem = new PresentationItem();
                    presentationItem.OutputFileName = s;
                    int index2 = 1;
                    do
                    {
                        String attr_type  = worksheet.Range(((char)((byte)'A' + index2)).ToString() + 1).Value2.ToString();
                        String attr_name  = worksheet.Range(((char)((byte)'A' + index2)).ToString() + 2).Value2.ToString();
                        String attr_value = worksheet.Range(((char)((byte)'A' + index2)).ToString() + index).Value2.ToString();

                        Log.Information("{0} {1} {2} {3}", ((char)((byte)'A' + index2)).ToString() + 1, attr_type, attr_name, attr_value);
                        presentationItem.Attributes.Add(new Attribute(attr_type, attr_name, attr_value));

                        index2++;
                        if (index2 == 20)
                        {
                            break;
                        }
                    } while (worksheet.Range(((char)((byte)'A' + index2)).ToString() + 1).Value2 != null && worksheet.Range(((char)((byte)'A' + index2)).ToString() + 1).Value2.ToString() != "");

                    index++;
                    presentationItems.Add(presentationItem);
                    if (index == 100)
                    {
                        break;
                    }
                } while (worksheet.Range("A" + index).Value2 != null && worksheet.Range("A" + index).Value2.ToString() != "");


                Log.Information("Closing Excel File");
                book.Close();

                Log.Information("Opening PowerPoint Applicaiton");
                applicationPowerPoint = new PowerPoint.Application();
                applicationPowerPoint.DisplayAlerts = PowerPoint.Enums.PpAlertLevel.ppAlertsNone;


                foreach (var presentationItem in presentationItems)
                {
                    Dictionary <int, List <PowerPoint.Shape> > powerpointShapesSheetDictionary = new Dictionary <int, List <PowerPoint.Shape> >();

                    Log.Information("Opening Presentation {0}", pptxSingle);
                    presentation = applicationPowerPoint.Presentations.Open(pptxSingle, true, true, true);

                    foreach (PowerPoint.Shape shape in presentation.SlideMaster.Shapes)
                    {
                        Log.Information("\tSlide Master:  Shape Name : {0} Size(w x h) : {1} x {2} Position(left x top) : {3} , {4}", shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);
                        if (shape.HasTextFrame == Office.Enums.MsoTriState.msoTrue && shape.TextFrame.HasText == Office.Enums.MsoTriState.msoTrue)
                        {
                            foreach (var attribute in presentationItem.Attributes)
                            {
                                if (attribute.type == "Text")
                                {
                                    string before = shape.TextFrame.TextRange.Text;
                                    shape.TextFrame.TextRange.Replace("|*" + attribute.name + "*|", attribute.value);
                                    string after = shape.TextFrame.TextRange.Text;
                                    if (before != after)
                                    {
                                        Log.Information("\t\t{0} >> {1}", before, after);
                                    }
                                }
                            }
                        }
                    }
                    Log.Information("Iterating all shapes in all slides and filtering shapes with name staring with \"#\"");
                    foreach (PowerPoint.Slide slide in presentation.Slides)
                    {
                        foreach (PowerPoint.Shape shape in slide.Shapes)
                        {
                            Log.Information("\tSlide No : {0} Shape Name : {1} Size(w x h) : {2} x {3} Position(left x top) : {4} , {5}", slide.SlideNumber, shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);
                            if (shape.HasTextFrame == Office.Enums.MsoTriState.msoTrue && shape.TextFrame.HasText == Office.Enums.MsoTriState.msoTrue)
                            {
                                foreach (var attribute in presentationItem.Attributes)
                                {
                                    if (attribute.type == "Text")
                                    {
                                        string before = shape.TextFrame.TextRange.Text;
                                        shape.TextFrame.TextRange.Replace("|*" + attribute.name + "*|", attribute.value);
                                        string after = shape.TextFrame.TextRange.Text;
                                        if (before != after)
                                        {
                                            Log.Information("\t\t{0} >> {1}", before, after);
                                        }
                                    }
                                }
                            }
                            foreach (var attribute in presentationItem.Attributes)
                            {
                                if (attribute.type == "Chart" && shape.Name == "|*" + attribute.name + "*|")
                                {
                                    string before = shape.Name;
                                    shape.Name = attribute.value;
                                    string after = shape.Name;
                                    if (before != after)
                                    {
                                        Log.Information("\t\t{0} >> {1}", before, after);
                                    }
                                }
                            }
                        }
                        Log.Information("");
                    }


                    String outputfile = Path.Combine(output_folder, new FileInfo(pptxSingle).Name);
                    Log.Information("Saving a copy of updated Presentation to {0}", outputfile);
                    presentation.SaveCopyAs(outputfile);

                    Log.Information("Closing Presentation");
                }

                presentation.Close();

                Log.Information("Closing PowerPoint Applicaiton");
                applicationPowerPoint.Quit();
                applicationPowerPoint.Dispose();

                Log.Information("Closing Excel Applicaiton");
                applicationExcel.Quit();
                applicationExcel.Dispose();

                Log.Information("Done");
            }
            catch (Exception e)
            {
                Log.Error("Fatal Error - " + e.ToString());
                thisForm.BeginInvoke((MethodInvoker)(() =>
                {
                    MessageBox.Show(thisForm, e.ToString(), "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }));
                try
                {
                    presentation.Close();
                }
                catch (Exception ee) { }
                try
                {
                    applicationPowerPoint.Quit();
                    applicationPowerPoint.Dispose();
                }
                catch (Exception ee) { }
                try
                {
                    book.Close();
                }
                catch (Exception ee) { }
                try
                {
                    applicationExcel.Quit();
                    applicationExcel.Dispose();
                }
                catch (Exception ee) { }
            }
        }
Пример #37
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");
        }
Пример #38
0
 private void button_close_Click(object sender, EventArgs e)
 {
     timer.Stop();
     pret.Close();
     ppt.Quit();
 }
Пример #39
0
        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();
        }
Пример #40
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();
                }
            }
        }
Пример #41
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();
                }
            }
        }
Пример #42
0
        private void doWork()
        {
            PowerPoint.Presentation presentation          = null;
            PowerPoint.Application  applicationPowerPoint = null;
            Excel.Workbook          book             = null;
            Excel.Application       applicationExcel = null;

            try
            {
                Dictionary <String, Excel.Shape> excelShapesDictionary = new Dictionary <string, Excel.Shape>();


                Log.Information("Opening Excel Applicaiton");
                applicationExcel = new Excel.Application();
                applicationExcel.DisplayAlerts = false;

                Log.Information("Opening Excel File {0}", xlsx);
                book = applicationExcel.Workbooks.Open(xlsx, true, true);

                Boolean flagDouble = false;
                Log.Information("Iterating all shapes in all sheets and filtering shapes with name staring with \"#\"");
                foreach (Excel.Worksheet sheet in book.Worksheets)
                {
                    foreach (Excel.Shape shape in sheet.Shapes)
                    {
                        if (shape.Name.Length > 1 && shape.Name.Substring(0, 1) == "#")
                        {
                            if (excelShapesDictionary.ContainsKey(shape.Name.ToLower().Trim()))
                            {
                                Log.Error("\t\tSheet: {0} Shape Name : {1} Error!!! Shape with the same name exists", sheet.Name, shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);
                                flagDouble = true;
                            }
                            else
                            {
                                Log.Information("\tSheet: {0} Shape Name : {1} ", sheet.Name, shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);

                                excelShapesDictionary.Add(shape.Name.ToLower().Trim(), shape);
                            }
                        }
                    }
                }
                if (flagDouble)
                {
                    Log.Error("ERROR -Found shapes with the same name : Duplicated shapes need to be manually renamed in the Excel file before proceeding. Terminating run.");
                    thisForm.BeginInvoke((MethodInvoker)(() =>
                    {
                        MessageBox.Show(thisForm, "Duplicated shapes need to be manually renamed in the Excel file before proceeding.\nSee logs for more information", "ERROR - Found shapes with the same name", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }));
                    goto closeWorkbook;
                }

                Log.Information("Opening PowerPoint Applicaiton");
                applicationPowerPoint = new PowerPoint.Application();
                applicationPowerPoint.DisplayAlerts = PowerPoint.Enums.PpAlertLevel.ppAlertsNone;


                foreach (string pptxSingle in pptx)
                {
                    Dictionary <int, List <PowerPoint.Shape> > powerpointShapesSheetDictionary = new Dictionary <int, List <PowerPoint.Shape> >();

                    Log.Information("Opening Presentation {0}", pptxSingle);
                    presentation = applicationPowerPoint.Presentations.Open(pptxSingle, true, true, false);


                    Log.Information("Iterating all shapes in all slides and filtering shapes with name staring with \"#\"");
                    Boolean datamissing = false;
                    foreach (PowerPoint.Slide slide in presentation.Slides)
                    {
                        foreach (PowerPoint.Shape shape in slide.Shapes)
                        {
                            if (shape.Name.Length > 1 && shape.Name.Substring(0, 1) == "#")
                            {
                                if (!excelShapesDictionary.ContainsKey(shape.Name.ToLower().Trim()))
                                {
                                    Log.Information("\t\tData Missing for Slide No : {0} Shape Name : {1} ", slide.SlideNumber, shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);
                                    datamissing = true;
                                }
                                else
                                {
                                    Log.Information("\tFound data for Slide No : {0} Shape Name : {1} ", slide.SlideNumber, shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);
                                }
                                if (!powerpointShapesSheetDictionary.ContainsKey(slide.SlideNumber))
                                {
                                    powerpointShapesSheetDictionary.Add(slide.SlideNumber, new List <PowerPoint.Shape>());
                                }
                                powerpointShapesSheetDictionary[slide.SlideNumber].Add(shape);
                            }
                            else
                            {
                                /*
                                 * Log.Information("\tFound data for Slide No : {0} Shape Name : {1} Size(w x h) : {2} x {3} Position(left x top) : {4} , {5}", slide.SlideNumber, shape.Name, shape.Width, shape.Height, shape.Left, shape.Top);
                                 * if (shape.HasTextFrame == Office.Enums.MsoTriState.msoTrue && shape.TextFrame.HasText == Office.Enums.MsoTriState.msoTrue)
                                 *  shape.TextFrame.TextRange.Replace("|*test*|", "123");
                                 */
                            }
                        }
                    }
                    if (datamissing)
                    {
                        Log.Error("ERROR - Match not found for shape/s in presentation : All shapes starting with \"#\"in the presentation should have matching shape in the excel.");
                        thisForm.BeginInvoke((MethodInvoker)(() =>
                        {
                            MessageBox.Show(thisForm, "All shapes starting with \"#\"in the presentation should have matching shape in the excel.\nSee logs for more information", "ERROR - Match not found for shape/s in presentation", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }));
                        goto closePresentation;
                    }


                    Log.Information("Start of Update");
                    foreach (int slideNo in powerpointShapesSheetDictionary.Keys)
                    {
                        foreach (var shape in powerpointShapesSheetDictionary[slideNo])
                        {
                            excelShapesDictionary[shape.Name.ToLower()].Copy();
                            Thread.Sleep(100);
                            PowerPoint.ShapeRange shapes = presentation.Slides[slideNo].Shapes.PasteSpecial(PowerPointEnums.PpPasteDataType.ppPasteJPG);
                            string shape_name            = shape.Name;
                            float  shape_top             = shape.Top;
                            float  shape_left            = shape.Left;

                            float shape_width  = shape.Width;
                            float shape_height = shape.Height;

                            shapes[1].Name = shape_name;
                            shapes[1].Top  = shape_top;
                            shapes[1].Left = shape_left;

                            shapes[1].ScaleWidth(shape.Width / shapes[1].Width, Office.Enums.MsoTriState.msoFalse);
                            //shapes[1].Height = shape_height;

                            shape.Delete();

                            Log.Information(" Updated {0} on slide {1}", shape_name, slideNo);
                        }
                    }
                    Log.Information("End of Update");

                    String outputfile = Path.Combine(output_folder, new FileInfo(pptxSingle).Name);
                    Log.Information("Saving a copy of updated Presentation to {0}", outputfile);
                    presentation.SaveCopyAs(outputfile);

closePresentation:
                    Log.Information("Closing Presentation");

                    presentation.Close();
                }


                Log.Information("Closing PowerPoint Applicaiton");
                applicationPowerPoint.Quit();
                applicationPowerPoint.Dispose();

closeWorkbook:
                Log.Information("Closing Excel File");
                book.Close();

                Log.Information("Closing Excel Applicaiton");
                applicationExcel.Quit();
                applicationExcel.Dispose();


                Log.Information("Done");
                thisForm.BeginInvoke((MethodInvoker)(() =>
                {
                    button1.Enabled = true;
                    button2.Enabled = true;
                    buttonFolder.Enabled = true;
                    button3.Enabled = true;

                    listView1.Enabled = true;
                    listView2.Enabled = true;
                    listView3.Enabled = true;
                    MessageBox.Show(thisForm, "Task Completed. Check logs for more info", "Completed", MessageBoxButtons.OK, MessageBoxIcon.None);
                }));
            }
            catch (Exception e)
            {
                Log.Error("Fatal Error - " + e.ToString());
                thisForm.BeginInvoke((MethodInvoker)(() =>
                {
                    MessageBox.Show(thisForm, e.ToString(), "Fatal Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    button1.Enabled = true;
                    button2.Enabled = true;
                    buttonFolder.Enabled = true;
                    button3.Enabled = true;

                    listView1.Enabled = true;
                    listView2.Enabled = true;
                    listView3.Enabled = true;
                }));
                try
                {
                    presentation.Close();
                }
                catch (Exception ee) { }
                try
                {
                    applicationPowerPoint.Quit();
                    applicationPowerPoint.Dispose();
                }
                catch (Exception ee) { }
                try
                {
                    book.Close();
                }
                catch (Exception ee) { }
                try
                {
                    applicationExcel.Quit();
                    applicationExcel.Dispose();
                }
                catch (Exception ee) { }
            }
        }
Пример #43
0
        private void ExecuteEvents(Timeline timeline, TimelineHandler handler)
        {
            try
            {
                foreach (var timelineEvent in handler.TimeLineEvents)
                {
                    try
                    {
                        _log.Trace($"PowerPoint event - {timelineEvent}");
                        WorkingHours.Is(handler);

                        if (timelineEvent.DelayBefore > 0)
                        {
                            Thread.Sleep(timelineEvent.DelayBefore);
                        }

                        if (timeline != null)
                        {
                            var processIds = ProcessManager.GetPids(ProcessManager.ProcessNames.PowerPoint).ToList();
                            if (processIds.Count > timeline.TimeLineHandlers.Count(o => o.HandlerType == HandlerType.PowerPoint))
                            {
                                return;
                            }
                        }

                        var powerApplication = new PowerPoint.Application
                        {
                            DisplayAlerts = PpAlertLevel.ppAlertsNone,
                            Visible       = MsoTriState.msoTrue
                        };

                        try
                        {
                            powerApplication.WindowState = PpWindowState.ppWindowMinimized;
                        }
                        catch (Exception e)
                        {
                            _log.Trace($"Could not minimize: {e}");
                        }

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

                        var writeSleep = ProcessManager.Jitter(100);
                        Thread.Sleep(writeSleep);

                        // save the document
                        var rand = RandomFilename.Generate();

                        var dir = timelineEvent.CommandArgs[0].ToString();
                        if (dir.Contains("%"))
                        {
                            dir = Environment.ExpandEnvironmentVariables(dir);
                        }

                        if (Directory.Exists(dir))
                        {
                            Directory.CreateDirectory(dir);
                        }

                        var path = $"{dir}\\{rand}.pptx";

                        //if directory does not exist, create!
                        _log.Trace($"Checking directory at {path}");
                        var f = new FileInfo(path).Directory;
                        if (f == null)
                        {
                            _log.Trace($"Directory does not exist, creating directory at {path}");
                            Directory.CreateDirectory(path);
                        }

                        try
                        {
                            if (File.Exists(path))
                            {
                                File.Delete(path);
                            }
                        }
                        catch (Exception e)
                        {
                            _log.Debug(e);
                        }

                        Thread.Sleep(5000);
                        presentation.SaveAs(path);
                        FileListing.Add(path);
                        Report(handler.HandlerType.ToString(), timelineEvent.Command,
                               timelineEvent.CommandArgs[0].ToString());

                        if (timelineEvent.DelayAfter > 0)
                        {
                            //sleep and leave the app open
                            _log.Trace($"Sleep after for {timelineEvent.DelayAfter}");
                            Thread.Sleep(timelineEvent.DelayAfter - writeSleep);
                        }

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

                        try
                        {
                            Marshal.ReleaseComObject(powerApplication);
                        }
                        catch { }

                        try
                        {
                            Marshal.FinalReleaseComObject(powerApplication);
                        }
                        catch { }

                        GC.Collect();
                    }
                    catch (Exception e)
                    {
                        _log.Debug(e);
                    }
                    finally
                    {
                        Thread.Sleep(5000);
                    }
                }
            }
            catch (Exception e)
            {
                _log.Debug(e);
            }
            finally
            {
                KillApp();
                _log.Trace("PowerPoint closing...");
            }
        }
Пример #44
0
        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();
        }