示例#1
0
        private bool BuildPowerPointFile(List <string> names)
        {
            //  open the base presentation
            // create the animations
            //  save as ... to the destination folder

            PowerPoint.Application   ppApplication   = null;
            PowerPoint.Presentations ppPresentations = null;
            PowerPoint.Presentation  ppPresentation  = null;

            try
            {
                ppApplication   = new PowerPoint.Application();
                ppPresentations = ppApplication.Presentations;

                //  to create a new presentation
                ppPresentation = ppPresentations.Add(MsoTriState.msoTrue);
                ppApplication.Activate();

                SlideWidthCentre  = (int)ppPresentation.PageSetup.SlideWidth / 2;
                SlideHeightCentre = (int)ppPresentation.PageSetup.SlideHeight / 2;

                ppPresentation.ApplyTemplate(Path.Combine(BaseSettingsFolder, TemplateFile));

                AddTitleSlide(ppPresentation, "My trust", "2015");

                AddAnimationNames(ppPresentation, names);

                //CentrePictures(ppPresentation);

                ppPresentation.SaveAs(Path.Combine(DestinationFolder, "AnimatedNames"),
                                      PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
            }
            catch (Exception e)
            {
                ProcessTextBox.AppendText(Environment.NewLine);
                ProcessTextBox.AppendText("Error: " + e.Message);

                return(false);
            }
            finally
            {
                try
                {
                    if (ppPresentation != null)
                    {
                        ppPresentation.Close();
                        ppApplication.Quit();

                        ppApplication = null;
                    }

                    GC.Collect();
                    GC.WaitForPendingFinalizers();

                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                catch (Exception e)
                {
                }
            }

            return(true);
        }