예제 #1
0
        public void Generate(SlideshowSettings settings, List <Student> students, PowerPointProgressBar progress, PowerPointGenerationCompleted callback)
        {
            string powerPointfile = "";

            if (settings.templateFilename != null && settings.templateFilename.Length > 0)
            {
                //If they are using the blank powerpoint use the resource one
                if (settings.templateFilename.ToLower() == "_blank.potx")
                {
                    powerPointfile = $@"{AppDomain.CurrentDomain.BaseDirectory}\{BLANK_POWERPOINT}";
                }
                else
                {
                    powerPointfile = settings.templateFilename;
                }

                //Create the powerpoint
                CreatePowerPoint(powerPointfile, settings, students, progress);

                callback(true);
            }
            else
            {
                callback(false);
            }
        }
예제 #2
0
        static void CreatePowerPoint(string template, SlideshowSettings settings, List <Student> students, PowerPointProgressBar progress)
        {
            progress.Minimum = 0;
            progress.Maximum = students.Count;
            progress.Value   = 0;

            Application  app;
            Presentation presentation;

            //Firstly ask where to save
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Title  = "Save your presentation...";
            dialog.Filter = "PowerPoint Presentations|*.pptx";

            //Show dialog and hopefully save after all that
            if (dialog.ShowDialog().Value == true)
            {
                //Create the overall slideshow
                app          = new Application();
                presentation = app.Presentations.Open(template, MsoTriState.msoFalse, MsoTriState.msoCTrue, MsoTriState.msoFalse);

                //Loop through the students
                foreach (Student student in students)
                {
                    //Add slides
                    AddPhotoSlide(settings, presentation, student);
                    AddAwardSlide(presentation, student);

                    //Increase progress values
                    progress.Value++;
                }

                //Save time
                presentation.SaveAs(dialog.FileName);

                //Clean up memory I hope
                presentation.Close();
                presentation = null;
                app          = null;
            }
        }