Ejemplo n.º 1
0
        public static void createPresentation(List <KeyValuePair <string, float> > titles)
        {
            Microsoft.Office.Interop.PowerPoint.Application oPowerPoint = new Microsoft.Office.Interop.PowerPoint.Application();
            oPowerPoint.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            System.Console.WriteLine("PowerPoint application created.");
            Presentations oPres   = oPowerPoint.Presentations;
            Presentation  oPre    = oPres.Add(MsoTriState.msoTrue);
            Slides        oSlides = oPre.Slides;

            int nr = 1;

            foreach (var title in titles)
            {
                //Console.WriteLine(title.Key+" - "+ title.Value);
                createNewSlide(oSlides, nr, title.Key, title.Value);
                nr += 1;
            }
            Console.WriteLine("Checking for three lines...");
            TwoLines.twoLinesFilter(oSlides);
            //additionally to avoid three lines
            Console.WriteLine("Additionally checking for three lines...");
            TwoLines.twoLinesFilter(oSlides);
            FilesController.saveSlides(oPre);
            //oPre.Close();
            //oPowerPoint.Quit();
            //System.Console.WriteLine("PowerPoint application quitted.");

            //Clean up the unmanaged COM resource.
            if (oSlides != null)
            {
                Marshal.FinalReleaseComObject(oSlides);
                oSlides = null;
            }
            if (oPre != null)
            {
                Marshal.FinalReleaseComObject(oPre);
                oPre = null;
            }
            if (oPres != null)
            {
                Marshal.FinalReleaseComObject(oPres);
                oPres = null;
            }
            if (oPowerPoint != null)
            {
                Marshal.FinalReleaseComObject(oPowerPoint);
                oPowerPoint = null;
            }
        }
Ejemplo n.º 2
0
        public static void TestPresentation()
        {
            Application   PowerPoint_App      = new Application();
            Presentations multi_presentations = PowerPoint_App.Presentations;
            Presentation  presentation        = multi_presentations.Open(FilesController.openFile());
            string        presentation_text   = "";

            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                foreach (var item in presentation.Slides[i + 1].Shapes)
                {
                    var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                    if (shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            var textRange = shape.TextFrame.TextRange;
                            //Console.WriteLine("sentence: " + textRange.Sentences().Length);

                            //check if there are more than two lines, and needs additional divisions
                            if (textRange.Lines().Count > 2)
                            {
                                int   slideNumber   = shape.Parent.SlideIndex;
                                float slideDuration = presentation.Slides[i + 1].SlideShowTransition.AdvanceTime;
                                presentation.Slides[i + 1].Delete();
                                //CustomLayout customLayout = presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];
                                if (textRange.Sentences().Count > 1)
                                {
                                    //the number represents to how many slides to divide
                                    int   divisionNumber = textRange.Sentences().Count;
                                    float duration       = TwoLines.durationAfterDivisions(slideDuration, divisionNumber);

                                    foreach (TextRange sentence in textRange.Sentences())
                                    {
                                        SlidesManipulation.createNewSlide(presentation.Slides, slideNumber++, sentence.Text.Trim(), duration);
                                    }
                                }
                                else
                                {
                                    int    divisionNumber = textRange.Lines().Count;
                                    float  duration       = TwoLines.durationAfterDivisions(slideDuration, divisionNumber / 2);
                                    string textFrmLines   = "";
                                    foreach (TextRange line in textRange.Lines())
                                    {
                                        if (textFrmLines.Length > 0)
                                        {
                                            textFrmLines += line.Text;
                                            SlidesManipulation.createNewSlide(presentation.Slides, slideNumber++, textFrmLines, duration);
                                            textFrmLines = "";
                                        }
                                        else
                                        {
                                            textFrmLines += line.Text;
                                        }
                                    }
                                }
                            }
                            var text = textRange.Text;
                            presentation_text += text + " ";
                        }
                    }
                }
            }
            PowerPoint_App.Quit();
            Console.WriteLine(presentation_text);
            FilesController.saveSlides(presentation);
        }
Ejemplo n.º 3
0
 public static void Prepare()
 {
     SlidesManipulation.createPresentation(TitlesManipulation.readTitlesFromFile(FilesController.openFile(), 25.0F));
     //MainSpeech.Run();
 }