Exemple #1
0
 /// <summary>
 /// Finishes off the Presentation (fills extra page)
 /// </summary>
 public void FinishPres()
 {
     objSlide = (Microsoft.Office.Interop.PowerPoint._Slide)objSlides._Index(sCount);
     oCount   = 1;
     AddText("This deck generated by eFlash", "Comic Sans MS", 40, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse, 50, 50, 800, 150);
     AddPic(Constant.ePath + "About.png", MsoTriState.msoFalse, MsoTriState.msoTrue, 200, 200, 350, 250);
     //AddPic("C:\\Program Files\\eFlash\\Data\\Media\\About.png", MsoTriState.msoFalse, MsoTriState.msoTrue, 200, 200, 350, 250);
 }
Exemple #2
0
 public void AddText(String text, PowerPoint._Slide slide, float left, float top, float width, float height)
 {
     PowerPoint.Shape     shape   = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, left, top, width, height);
     PowerPoint.TextRange textRng = shape.TextFrame.TextRange;
     textRng.Font.Name = "微软雅黑";
     textRng.Font.Size = 24;
     textRng.Font.Bold = MsoTriState.msoCTrue;
     textRng.Text      = text;
 }
Exemple #3
0
 /// <summary>
 /// 往正在播放的幻灯片后面插入一个Slide
 /// </summary>
 /// <param name="fileAddress"></正在播放幻灯片的地址>
 /// <param name="fileName"></正在播放幻灯片的名字>
 private void InsertAPage(string fileAddress, string fileName)
 {
     objSlide             = objSlides.Add(CURRENTPAGE + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
     objTextRng           = objSlide.Shapes[1].TextFrame.TextRange;
     objTextRng.Text      = "From " + fileName.Substring(0, fileName.Length - 4);
     objTextRng.Font.Name = "Comic Sans MS";
     objTextRng.Font.Size = 48;
     objSlide.Shapes.AddPicture(@fileAddress, MsoTriState.msoFalse, MsoTriState.msoTrue,
                                150, 150, 500, 350);
 }
Exemple #4
0
        public void CreateNewPPT()
        {
            application        = new PowerPoint.Application();
            pptPresentationSet = application.Presentations;
            pptPresentation    = pptPresentationSet.Open(_fileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            //customLayout = pptPresentationSet.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];
            pptSlides = pptPresentation.Slides;
            pptSlide  = pptSlides.AddSlide(1, customLayout);

            textRng           = pptSlide.Shapes[1].TextFrame.TextRange;
            textRng.Font.Name = textDefaultFontName;
            textRng.Font.Size = textDefaultFontSize;
        }
 public void SetHead(AirwayCT.Entity.AirwayPatient patient)
 {
     headSlide = powerPointDAO.AddNewSlide();
     powerPointDAO.AddText(patient.Name, headSlide, 50, 50, 300, 40);
     powerPointDAO.AddText(patient.Age, headSlide, 50, 80, 300, 40);
     powerPointDAO.AddText(patient.Sex, headSlide, 50, 110, 300, 40);
     powerPointDAO.AddText(patient.Institution, headSlide, 50, 140, 300, 40);
     if (!string.IsNullOrEmpty(_baseFolder))
     {
         string   dest3DDir = Path.Combine(_baseFolder, "Snapshot");
         string[] files     = Directory.GetFiles(dest3DDir);
         if (files.Length > 0)
         {
             powerPointDAO.AddImage(files[0], headSlide, 340, 50, 350, 350);
         }
     }
 }
Exemple #6
0
        internal void CreateNewPPT(string title)
        {
            // Create the Presentation File
            pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);

            pptPresentation.PageSetup.SlideSize   = Powerpoint.PpSlideSizeType.ppSlideSizeCustom; //equals 16*9, but also fits the typical DIN A4 Width (excluding DIN A4 Border)
            pptPresentation.PageSetup.SlideWidth  = (float)MathHelper.ConvertCmToPoint(SlideWidthCm);
            pptPresentation.PageSetup.SlideHeight = (float)MathHelper.ConvertCmToPoint(SlideHeightCm);

            pptPresentation.PageSetup.SlideOrientation = Microsoft.Office.Core.MsoOrientation.msoOrientationVertical;
            var customLayout = pptPresentation.SlideMaster.CustomLayouts[7];

            // Create new Slide
            slides = pptPresentation.Slides;
            slide  = slides.AddSlide(1, customLayout);
            //Test
            slide.FollowMasterBackground        = Microsoft.Office.Core.MsoTriState.msoFalse;
            slide.Background.Fill.ForeColor.RGB = 0;
        }
Exemple #7
0
 public PowerPoint.Shape GetActiveShape()
 {
     PowerPoint._Slide slide = GetActiveSlide();
     if (slide == null)
     {
         return(null);
     }
     if (slide.Shapes.Count < 1)
     {
         return(null);
     }
     PowerPoint.Shape shape = null;
     try
     {
         shape = PowerpointApplication.ActiveWindow.Selection.ShapeRange[1];
     }
     catch
     {
         shape = null;
     }
     return(shape);
 }
Exemple #8
0
        /// <summary>
        /// Get the shape at given coodinates
        /// </summary>
        /// <param name="slidePosition"></param>
        /// <param name="shapePosition"></param>
        /// <returns></returns>
        public PowerPoint.Shape getShape(int slidePosition, int shapeId)
        {
            PowerPoint._Slide slide = GetSlide(slidePosition);
            if (slide == null)
            {
                return(null);
            }
            int count = PowerpointPresentation.Slides.Count;

            if (count <= 0)
            {
                return(null);
            }
            foreach (PowerPoint.Shape shape in slide.Shapes)
            {
                if (shape.Id == shapeId)
                {
                    return(shape);
                }
            }
            return(null);
        }
 /// <summary>
 /// 设置三维视图旋转图片的位置
 /// </summary>
 public void AddRotate3DImages()
 {
     if (!string.IsNullOrEmpty(_baseFolder))
     {
         string   dest3DDir = Path.Combine(_baseFolder, "Snapshot");
         string[] files     = Directory.GetFiles(dest3DDir);
         if (files.Length > 0)
         {
             rotate3DSlide = powerPointDAO.AddNewSlide();
             powerPointDAO.AddText("三维图像", rotate3DSlide, 30, 10, 300, 40);
             for (int i = 0; i < files.Length; i++)
             {
                 if (i >= 3)
                 {
                     powerPointDAO.AddImage(files[i], rotate3DSlide, 200 * (i - 3) + (20 * (i - 3)) + 50, 265, 200, 200);
                 }
                 else
                 {
                     powerPointDAO.AddImage(files[i], rotate3DSlide, 200 * i + (i * 20) + 50, 50, 200, 200);
                 }
             }
         }
     }
 }
        private void createSlide(ArrayList selectedUrls)
        {
            // Create new Slide
            slides = pptPresentation.Slides;
            slide  = slides.AddSlide(slideNumber, customLayout);
            //increment slide number
            slideNumber++;
            // Add title
            objText           = slide.Shapes[1].TextFrame.TextRange;
            objText.Text      = this.MainWindowTitleText.Text;
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

            System.Windows.Documents.TextRange textRange = new System.Windows.Documents.TextRange(this.MainWindowSlideText.Document.ContentStart, this.MainWindowSlideText.Document.ContentEnd);

            objText      = slide.Shapes[2].TextFrame.TextRange;
            objText.Text = textRange.Text;

            Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
            foreach (string url in selectedUrls)
            {
                slide.Shapes.AddPicture(url, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);
            }
        }
Exemple #11
0
        private void examplePresentation()
        {
            String presentationTitle = "Proposta de Trabalho 3";

            //Add a new slide with Title Layout
            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitle);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = presentationTitle;
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Carlos Ribeiro 71945\nGisela Pinto 76397";
            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Falta a minha apresentação, eu sou o Salvador, o assistente pessoal do power point";


            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "PowerPoint";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Plataforma para apresentações mais profissionais.\n" +
                                              "Serve de guideline numa apresentação e também para partilhar informação acerca de um tema.\n" +
                                              "O objetivo do trabalho é facilitar ainda mais a sua utilização.";
            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "O Power Point é fixe para apresentar trabalhos!";

            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Comandos Single";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Para estes escolhemos os comandos que só estavam representados ou em gestos ou em voz. São os seguintes:.\n" +
                                              "Abrir/Fechar Power Point (Speech)\n" +
                                              "Salta de/para (Speech)\n" +
                                              "Zoom In/Out (Gestos)" +
                                              "Crop In/Out (Gestos)" +
                                              "Ler Titulo, Texto ou Notas (Speech)";
            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "O Power Point é fixe para apresentar trabalhos!";


            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Comandos Redundancy";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Avançar Slide\n" +
                                              "Recuar Slide.\n" +
                                              "Abrir Modo apresentação.\n" +
                                              "Fechar Modo Apresentação.\n";
            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "O Power Point é fixe para apresentar trabalhos!";


            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Comandos Complementary";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Escolhemos para complementariedade o Mudar tema. Inicialmente dizemos tema e o respetivo número e de seguida executamos o gesto correspondente\n";
            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "O Power Point é fixe para apresentar trabalhos!";


            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Imagem";
            tShape = oSlide.Shapes[2];
            oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Kitty cat power!";


            //Resize image
            OpenFileDialog open = new OpenFileDialog();

            string workingDirectory = Environment.CurrentDirectory;
            string parentDirectory  = Directory.GetParent(workingDirectory).Parent.FullName;

            open.FileName = parentDirectory + @"\kitty_cat.jpg";
            Console.WriteLine(open.FileName);
            FileInfo file        = new FileInfo(open.FileName);
            var      sizeInBytes = file.Length;

            Bitmap img = new Bitmap(open.FileName);

            var imageHeight = img.Height;
            var imageWidth  = img.Width;


            //to move image just modify left top from the function AddPicture
            tShape = oSlide.Shapes.AddPicture(open.FileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, imageWidth, imageHeight);

            imgWidth  = tShape.Width;
            imgHeight = tShape.Height;
        }
Exemple #12
0
 /// <summary>
 /// 往正在播放的幻灯片后面插入一个Slide
 /// </summary>
 /// <param name="fileAddress"></正在播放幻灯片的地址>
 /// <param name="fileName"></正在播放幻灯片的名字>
 private void InsertAPage(string fileAddress, string fileName)
 {
     objSlide = objSlides.Add(CURRENTPAGE + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
     objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
     objTextRng.Text = "From " + fileName.Substring(0, fileName.Length - 4);
     objTextRng.Font.Name = "Comic Sans MS";
     objTextRng.Font.Size = 48;
     objSlide.Shapes.AddPicture(@fileAddress, MsoTriState.msoFalse, MsoTriState.msoTrue,
         150, 150, 500, 350);
 }
Exemple #13
0
 /// <summary>
 /// Finishes off the Presentation (fills extra page)
 /// </summary>
 public void FinishPres()
 {
     objSlide = (Microsoft.Office.Interop.PowerPoint._Slide) objSlides._Index(sCount);
     oCount = 1;
     AddText("This deck generated by eFlash", "Comic Sans MS", 40, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse, 50, 50, 800, 150);
     AddPic(Constant.ePath + "About.png", MsoTriState.msoFalse, MsoTriState.msoTrue, 200, 200, 350, 250);
     //AddPic("C:\\Program Files\\eFlash\\Data\\Media\\About.png", MsoTriState.msoFalse, MsoTriState.msoTrue, 200, 200, 350, 250);
 }
Exemple #14
0
 /// <summary>
 /// Adds a new slide to presentation.
 /// </summary>
 public void AddSlide()
 {
     oCount = 1;
     objSlide = objSlides.Add(sCount++, PowerPoint.PpSlideLayout.ppLayoutBlank);
 }
Exemple #15
0
        private void MmiC_Message(object sender, MmiEventArgs e)
        {
            Console.WriteLine(e.Message);
            var     doc  = XDocument.Parse(e.Message);
            var     com  = doc.Descendants("command").FirstOrDefault().Value;
            dynamic json = JsonConvert.DeserializeObject(com);

            Console.WriteLine(json);
            Console.WriteLine((string)json.recognized[0].ToString());
            Console.WriteLine((string)json.keys[0].ToString());

            Tts t = new Tts();

            //TODO: See where should have the method cleanAllConfirmations()
            //https://docs.microsoft.com/en-us/office/vba/api/powerpoint.slide
            switch ((string)json.keys[0].ToString())
            {
            //TODO: pôr tudo o que está para baixo aqui dentro
            case "openPowerPoint":
                oPowerPoint   = new PowerPoint.Application();
                oPresentation = oPowerPoint.Presentations.Add();
                break;

            case "slide":
                switch ((string)json.recognized[0].ToString())
                {
                case "NEXT_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Next();
                    break;

                case "PREVIOUS_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Previous();
                    break;

                case "NEXT":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                    break;

                case "PREVIOUS":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex - 1].Select();
                    break;

                case "JUMP_TO":
                    oPresentation.Slides[Int32.Parse(json.recognized[1].ToString())].Select();
                    break;

                case "JUMP_TO_SLIDE_PRESENTATION":
                    oPresentation.SlideShowWindow.View.GotoSlide(Int32.Parse(json.recognized[1].ToString()));
                    break;

                case "NEW_SLIDE":
                    if (oPresentation.Slides.Count == 0)
                    {
                        oPresentation.Slides.Add(1, PowerPoint.PpSlideLayout.ppLayoutTitle).Select();
                    }
                    else
                    {
                        oPresentation.Slides.Add(oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1, PowerPoint.PpSlideLayout.ppLayoutTitle).Select();;
                    }
                    break;


                case "REMOVE_SLIDE":
                    if (oPresentation.Slides.Count > 0)
                    {
                        oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Delete();
                        t.Speak("Slide removido!");
                    }
                    else
                    {
                        t.Speak("Não existe nenhum slide.");
                    }
                    break;
                }
                break;

            case "read":
                switch ((string)json.recognized[0].ToString())
                {
                case "TITLE":
                    var title = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Shapes.Title.TextFrame.TextRange.Text;
                    t.Speak(title);
                    break;

                case "TEXT":
                    var text = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(text);
                    break;

                case "NOTE":
                    var notas = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex].NotesPage.Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(notas);
                    break;

                case "TITLE_PRESENTATION":
                    var title_pres = oPresentation.SlideShowWindow.View.Slide.Shapes.Title.TextFrame.TextRange.Text;
                    t.Speak(title_pres);
                    break;

                case "TEXT_PRESENTATION":
                    var text_pres = oPresentation.SlideShowWindow.View.Slide.Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(text_pres);
                    break;

                case "NOTE_PRESENTATION":
                    var note_pres = oPresentation.SlideShowWindow.View.Slide.NotesPage.Shapes[2].TextFrame.TextRange.Text;
                    t.Speak(note_pres);
                    break;
                }
                break;



            case "theme":
                switch ((string)json.recognized[0].ToString())
                {
                case "1":

                    string dir = @"C:\Program Files (x86)\Microsoft Office\";
                    if (Directory.Exists(dir))
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Facet.thmx");
                    }
                    else
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Facet.thmx");
                    }


                    break;

                case "2":

                    string dir1 = @"C:\Program Files (x86)\Microsoft Office\";
                    if (Directory.Exists(dir1))
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Gallery.thmx");
                    }
                    else
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Gallery.thmx");
                    }
                    break;

                case "3":
                    string dir2 = @"C:\Program Files (x86)\Microsoft Office\";
                    if (Directory.Exists(dir2))
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files (x86)\Microsoft Office\root\Document Themes 16\Ion.thmx");
                    }
                    else
                    {
                        oPresentation.ApplyTheme(@"C:\Program Files\Microsoft Office\root\Document Themes 16\Ion.thmx");
                    }
                    break;
                }
                break;

            case "save":
                oPresentation.Save();
                break;

            case "color":
                Slide     activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];;
                TextRange textRange   = activeSlide.Shapes.Title.TextFrame.TextRange;;
                if (json.recognized.Count > 1)
                {
                    switch ((string)json.recognized[0].ToString())
                    {
                    /*case "TITLE":
                     *  activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
                     *  textRange = activeSlide.Shapes.Title.TextFrame.TextRange;
                     *  break;*/
                    case "TEXT":
                        activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
                        textRange   = activeSlide.Shapes[2].TextFrame.TextRange;
                        break;
                    }
                }
                switch ((string)json.recognized[1].ToString())
                {
                case "YELLOW":
                    textRange.Font.Color.RGB = 379903;
                    t.Speak("Mudado para Amarelo");
                    break;

                case "RED":
                    textRange.Font.Color.RGB = 255;
                    t.Speak("Mudado para Vermelho");
                    break;

                case "BLUE":
                    textRange.Font.Color.RGB = 16711680;
                    t.Speak("Mudado para Azul");
                    break;

                case "GREEN":
                    textRange.Font.Color.RGB = 2540123;
                    t.Speak("Mudado para Verde");
                    break;

                case "BLACK":
                    textRange.Font.Color.RGB = 0;
                    t.Speak("Mudado para Preto");
                    break;
                }
                break;

            case "example":
                String presentationTitle = "Proposta de Trabalho 2";

                //Save the file
                //oPresentation.SaveAs(presentationTitle, PowerPoint.PpSaveAsFileType.ppSaveAsPresentation);

                //Add a new slide with Title Layout
                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitle);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = presentationTitle;
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Carlos Ribeiro\nGisela Pinto";

                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = "Tema";
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Interação por voz do Powerpoint";

                //Add Image
                //tShape = oSlide.Shapes.AddPicture("imagePowerPoint.png", Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0);

                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = "Features para utilizar durante uma apresentação";
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Avançar slide.\n" +
                                                  "Recuar slide.\n" +
                                                  "Saltar slides, por exemplo mudar do slide 2 para o 5.\n" +
                                                  "Ler texto de um slide.\n" +
                                                  "Ler notas de um slide fazendo assim a apresentação completa.\n" +
                                                  "Terminar a apresentação.\n" +
                                                  "Controlar um video que esteja integrado no slide(Iniciar/ parar).";

                oSlide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Eu, Salvador, estou a ler notas do slide 3, beijinhos e abraços";

                //oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);

                //tShape = oSlide.Shapes.AddMediaObject2(@"C:\Users\Gisela Pinto\Documents\IM\Trabalho1\im_2019_2020\Basis4Assignment2\ppt.mp4", MsoTriState.msoTrue, MsoTriState.msoTrue, 8, 8, 530, 530);

                oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
                tShape = oSlide.Shapes.Title;
                tShape.TextFrame.TextRange.Text = "Features para construção de uma apresentação";
                tShape = oSlide.Shapes[2];
                tShape.TextFrame.TextRange.Text = "Iniciar a criação da apresentação com um dos temas sugeridos.\n" +
                                                  "Acrescentar um novo slide em branco/ duplicado.\n" +
                                                  "Remover determinado slide.\n" +
                                                  "Escrever o que o utilizador ditar.\n" +
                                                  "Guardar alterações.\n" +
                                                  "Mudar cor do texto(algumas cores mais usadas).";
                oPresentation.Slides[oSlide.SlideIndex].Select();
                break;

            case "presentation":
                switch ((string)json.recognized[0].ToString())
                {
                case "START":
                    oPresentation.SlideShowSettings.Run();
                    break;

                case "STOP_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Exit();
                    break;
                }
                break;

            case "close":
                oPowerPoint.Quit();
                System.Diagnostics.Process[] pros = System.Diagnostics.Process.GetProcesses();
                for (int i = 0; i < pros.Count(); i++)
                {
                    if (pros[i].ProcessName.ToLower().Contains("powerpnt"))
                    {
                        pros[i].Kill();
                    }
                }
                break;
            }

            /*
             *
             *
             * //Edition
             *
             *
             *          case "COLOR_TITLE":
             *              var activeSlide = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
             *              rangeTitle = activeSlide.Shapes.Title.TextFrame.TextRange;
             *              if (json.recognized.Count > 1) {
             *                  switch ((string)json.recognized[1].ToString()) {
             *                      case "YELLOW":
             *                          rangeTitle.Font.Color.RGB = 379903;
             *                          t.Speak("Mudado para Amarelo");
             *                          break;
             *                      case "RED":
             *                          rangeTitle.Font.Color.RGB = 255;
             *                          t.Speak("Mudado para Vermelho");
             *                          break;
             *                      case "BLUE":
             *                          rangeTitle.Font.Color.RGB = 16711680;
             *                          t.Speak("Mudado para Azul");
             *                          break;
             *                      case "GREEN":
             *                          rangeTitle.Font.Color.RGB = 2540123;
             *                          t.Speak("Mudado para Verde");
             *                          break;
             *                      case "BLACK":
             *                          rangeTitle.Font.Color.RGB = 0;
             *                          t.Speak("Mudado para Preto");
             *                          break;
             *                  }
             *              }else {
             *                  t.Speak("Deseja mudar para que cor?");
             *                  selectColorTitle = true;
             *              }
             *              break;
             *
             *          case "COLOR_TEXT":
             *              t.Speak("Deseja mudar para que cor?");
             *              var activeSlide2 = oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex];
             *              rangeShape = activeSlide2.Shapes[2].TextFrame.TextRange;
             *              if (json.recognized.Count > 1) {
             *                  switch ((string)json.recognized[1].ToString()) {
             *                      case "YELLOW":
             *                          rangeTitle.Font.Color.RGB = 379903;
             *                          t.Speak("Mudado para Amarelo");
             *                          break;
             *                      case "RED":
             *                          rangeTitle.Font.Color.RGB = 255;
             *                          t.Speak("Mudado para Vermelho");
             *                          break;
             *                      case "BLUE":
             *                          rangeTitle.Font.Color.RGB = 16711680;
             *                          t.Speak("Mudado para Azul");
             *                          break;
             *                      case "GREEN":
             *                          rangeTitle.Font.Color.RGB = 2540123;
             *                          t.Speak("Mudado para Verde");
             *                          break;
             *                      case "BLACK":
             *                          rangeTitle.Font.Color.RGB = 0;
             *                          t.Speak("Mudado para Preto");
             *                          break;
             *                  }
             *              } else {
             *                  t.Speak("Deseja mudar para que cor?");
             *                  selectColorText = true;
             *              }
             *              break;
             *
             *          case "YELLOW":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 379903;
             *                  t.Speak("Mudado para Amarelo");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 379903;
             *                  t.Speak("Mudado para Amarelo");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *
             *              }
             *              break;
             *
             *          case "RED":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 255;
             *                  t.Speak("Mudado para Vermelho");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 255;
             *                  t.Speak("Mudado para Vermelho");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *              }
             *              break;
             *
             *          case "BLUE":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 16711680;
             *                  t.Speak("Mudado para Azul");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 16711680;
             *                  t.Speak("Mudado para Azul");
             *              } else {
             *
             *                  t.Speak("Devo ter percebido mal.");
             *
             *              }
             *              break;
             *
             *          case "GREEN":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 2540123;
             *                  t.Speak("Mudado para Verde");
             *              } else if (selectColorText == true) {
             *                  selectColorText = false;
             *                  rangeShape.Font.Color.RGB = 2540123;
             *                  t.Speak("Mudado para Verde");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *              }
             *              break;
             *
             *          case "BLACK":
             *              if (selectColorTitle == true) {
             *                  selectColorTitle = false;
             *                  rangeTitle.Font.Color.RGB = 0;
             *                  t.Speak("Mudado para Preto");
             *              } else if (selectColorText == true) {
             *                  selectColorTitle = false;
             *                  rangeShape.Font.Color.RGB = 0;
             *                  t.Speak("Mudado para Preto");
             *              } else {
             *                  t.Speak("Devo ter percebido mal.");
             *              }
             *              break;
             *
             */
        }
Exemple #16
0
        /// <summary>
        /// スタンプ貼付け処理
        /// </summary>
        protected override Boolean SetStamp(Secrecy secrecyLevel)
        {
            // 一時ファイル名取得
            string imageFilePath = System.IO.Path.GetTempFileName();

            Bitmap bmpSrc = null;

            try
            {
                // 現在開いているPowerPointの取得
                PowerPoint.Application pptApp = (PowerPoint.Application)global::PowerPointAddInSAB.Globals.ThisAddIn.Application;

                // 先頭のスライド取得
                PowerPoint._Slide slide = (PowerPoint.Slide)pptApp.ActivePresentation.Slides[1];


                // スタンプ表示OFF・区分"以外"の場合はスタンプをセットしない
                // スタンプ画像を削除して終了
                if (this.chkChange.Checked == false || this.rdoElse.Checked == true)
                {
                    // 指定した名前のオブジェクトを削除
                    this.DeletePowerPointShapes(ref pptApp, this.STAMP_SHAPE_NAME);

                    return(true);
                }


                // スタンプ画像をリソースから取得
                bmpSrc = this.GetStampImage(secrecyLevel);

                // 画像が取得できない場合は中断
                if (bmpSrc == null)
                {
                    return(false);
                }

                // スタンプ倍率変更
                double dStampWidth  = bmpSrc.Width / STAMP_MAGNIFICATION;
                double dStampHeight = bmpSrc.Height / STAMP_MAGNIFICATION;

                // 透過処理
                float alpha = (float)(this.nudAlpha.Value * (decimal)0.01);
                bmpSrc = this.CreateAlphaImage(bmpSrc, alpha);

                // ファイルを一時保存
                bmpSrc.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png);

                // スタンプの水平位置を PPTの幅 - 画像の幅 で算出
                float leftLocation = slide.Master.Width - (float)dStampWidth;


                // 指定した名前のオブジェクトを削除
                this.DeletePowerPointShapes(ref pptApp, this.STAMP_SHAPE_NAME);


                // 画像貼付処理
                PowerPoint.Shape stampShape = slide.Shapes.AddPicture(imageFilePath,
                                                                      MsoTriState.msoFalse,
                                                                      MsoTriState.msoTrue,
                                                                      leftLocation,
                                                                      0,
                                                                      (float)dStampWidth,
                                                                      (float)dStampHeight);
                // 貼付けた画像のオブジェクト名を設定
                stampShape.Name = this.STAMP_SHAPE_NAME;
            }
            catch
            {
                // スタンプ貼り付け失敗
                return(false);
            }
            finally
            {
                // 一時ファイル削除
                System.IO.File.Delete(imageFilePath);

                // 解放
                if (bmpSrc != null)
                {
                    bmpSrc.Dispose();
                }
            }

            return(true);
        }
Exemple #17
0
        /// <summary>
        /// スタンプ貼付け処理
        /// </summary>
        /// <param name="secrecyLevel">機密区分</param>
        /// <param name="fileName">ファイル名</param>
        /// <returns>true:成功 false:失敗</returns>
        public Boolean SetStampPowerPoint(Secrecy secrecyLevel, string fileName)
        {
            // 一時ファイル名取得
            string imageFilePath = System.IO.Path.GetTempFileName();

            PowerPoint.Application   pptApp  = null;
            PowerPoint.Presentations ppPress = null;
            PowerPoint.Presentation  pptFile = null;
            PowerPoint._Slide        slide   = null;
            Bitmap bmpSrc = null;

            try
            {
                // 現在開いているPowerPointの取得
                pptApp  = new PowerPoint.Application();
                ppPress = pptApp.Presentations;

                foreach (PowerPoint.Presentation ppt in ppPress)
                {
                    if (ppt.FullName == fileName)
                    {
                        // 既に開いている場合
                        return(false);
                    }
                }

                pptFile = ppPress.Open(
                    fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse
                    );

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

                // 先頭のスライド取得
                slide = (PowerPoint.Slide)pptFile.Slides[1];

                // スタンプ表示OFF・区分"以外"の場合はスタンプをセットしない
                // スタンプ画像を削除して終了
                if (this.chkChange.Checked == false || this.rdoElse.Checked == true)
                {
                    // 指定した名前のオブジェクトを削除
                    this.DeletePowerPointShapes(ref pptApp, ref pptFile, this.STAMP_SHAPE_NAME);

                    return(true);
                }


                // スタンプ画像をリソースから取得
                bmpSrc = this.GetStampImage(secrecyLevel);

                // 画像が取得できない場合は中断
                if (bmpSrc == null)
                {
                    return(false);
                }

                // スタンプ倍率変更
                double dStampWidth  = bmpSrc.Width / STAMP_MAGNIFICATION;
                double dStampHeight = bmpSrc.Height / STAMP_MAGNIFICATION;

                // 透過処理
                float alpha = (float)(this.nudAlpha.Value * (decimal)0.01);
                bmpSrc = this.CreateAlphaImage(bmpSrc, alpha);

                // ファイルを一時保存
                bmpSrc.Save(imageFilePath, System.Drawing.Imaging.ImageFormat.Png);

                // スタンプの水平位置を PPTの幅 - 画像の幅 で算出
                float leftLocation = slide.Master.Width - (float)dStampWidth;


                // 指定した名前のオブジェクトを削除
                this.DeletePowerPointShapes(ref pptApp, ref pptFile, this.STAMP_SHAPE_NAME);


                // 画像貼付処理
                PowerPoint.Shape stampShape = slide.Shapes.AddPicture(imageFilePath,
                                                                      MsoTriState.msoFalse,
                                                                      MsoTriState.msoTrue,
                                                                      leftLocation,
                                                                      0,
                                                                      (float)dStampWidth,
                                                                      (float)dStampHeight);
                // 貼付けた画像のオブジェクト名を設定
                stampShape.Name = this.STAMP_SHAPE_NAME;

                if (pptFile != null)
                {
                    pptFile.Save();
                }
            }
            catch
            {
                Encoding sjisEnc    = Encoding.GetEncoding("Shift_JIS");
                int      FileLength = sjisEnc.GetByteCount(fileName);
                // ファイルパス最大200バイト以上の場合は実行不可とする
                if (FileLength >= FILEPATH_OUT_RANGE)
                {
                    // 文字数エラー
                    string Msg = string.Format(Resources.msgErrorArgumentOutOfRange + "{0}", fileName);
                    MessageBox.Show(Msg, Resources.msgError, MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
                return(false);
            }
            finally
            {
                if (pptFile != null)
                {
                    pptFile.Close();
                }

                slide   = null;
                pptFile = null;
                ppPress = null;
                pptApp  = null;

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

                // 一時ファイル削除
                System.IO.File.Delete(imageFilePath);

                if (bmpSrc != null)
                {
                    bmpSrc.Dispose();
                }
            }

            return(true);
        }
Exemple #18
0
        /// <summary>
        /// Generates PowerPoint Slide with given Title, Body and selected images
        /// </summary>
        public static string generatePowerPointSlide(string titleText, string bodyText, List <ImageToUse> imagesToPPT)
        {
            string status         = "Success";
            string powerPointPath = System.IO.Path.Combine(Environment.CurrentDirectory, "ppSample.pptx");

            Microsoft.Office.Interop.PowerPoint.Application  pptApplication = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation;

            if (File.Exists(powerPointPath))
            {
                // Append to existing PowerPoint
                Microsoft.Office.Interop.PowerPoint.Presentations pres = pptApplication.Presentations;
                pptPresentation = pres.Open(powerPointPath);
            }
            else
            {
                // Create new PowerPoint
                pptPresentation = pptApplication.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
            }

            Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout =
                pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

            // Acquire slides from presentation
            Microsoft.Office.Interop.PowerPoint.Slides slides = pptPresentation.Slides;

            // Append new slide to end of presentation
            Microsoft.Office.Interop.PowerPoint._Slide slide = slides.AddSlide(slides.Count + 1, customLayout);

            Microsoft.Office.Interop.PowerPoint.TextRange objText;

            // Add title from titleTextArea
            objText           = slide.Shapes[1].TextFrame.TextRange;
            objText.Text      = titleText;
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

            // Add body from bodyTextArea
            objText           = slide.Shapes[2].TextFrame.TextRange;
            objText.Text      = bodyText;
            objText.Font.Name = "Arial";
            objText.Font.Size = 20;

            Microsoft.Office.Interop.PowerPoint.Shapes shapes = slide.Shapes;
            string imagePath = System.IO.Path.Combine(Environment.CurrentDirectory, "image.jpg");
            int    imageX    = 50;

            // Go through all images, if image was highlighted in grid, post it inside PPT
            foreach (ImageToUse imageToUse in imagesToPPT)
            {
                if (imageToUse.use)
                {
                    // Save all images being used
                    var encoder = new PngBitmapEncoder();
                    encoder.Frames.Add(BitmapFrame.Create((BitmapSource)imageToUse.bitmapImage));
                    using (FileStream stream = new FileStream(imagePath, FileMode.Create)) encoder.Save(stream);

                    // Insert all images into PPT
                    shapes.AddPicture(imagePath, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, imageX, 350, 100, 100);
                    imageX += 100;

                    // Delete all images when done with them
                    File.Delete(imagePath);
                }
            }

            try
            {
                // Save Power Point
                pptPresentation.SaveAs(powerPointPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
            }
            catch (Exception exception)
            {
                status = "Problem while trying to save PowerPoint:\n" + exception.ToString();
            }

            return(status);
            // pptPresentation.Close();
            // pptApplication.Quit();
        }
 public void InsertText(PowerPoint._Slide slide, String text, float left, float top, float width, float height)
 {
     PowerPoint.Shape     shape   = slide.Shapes.AddTextbox(MsoTextOrientation.msoTextOrientationHorizontal, left, top, width, height);
     PowerPoint.TextRange textRng = shape.TextFrame.TextRange;
     textRng.Text = text;
 }
Exemple #20
0
        public void redata(ref int s, ref List<question> questions, ref int choices_no1, ref int data_format)
        {
            float total = 0;
            Graph.SeriesCollection ss = questions[s].datasheet.Application.Chart().SeriesCollection();
            Graph.Points kj;
            kj = ss.Item(1).Points();
            objSlide = objPres.Slides._Index(s + 1);
            objShapes = objSlide.Shapes;

            for (int i = 2; i <= choices_no1 + 1; i++)
            {
                total = (total + questions[s].values[i - 2]);
            }

            if (data_format == 2)
            {
                for (int i = 2; i <= choices_no1 + 1; i++)
                {

                    questions[s].datasheet.Cells[2, i] = questions[s].values[i - 2];

                }

              questions[s].datasheet.Application.Chart().Refresh();

            objShape2 = objShapes[4];
            objShape2.TextEffect.Text = "Total" + " " + total.ToString();
            }

            else if (data_format == 1)
            {
                for (int i = 2; i <= choices_no1 + 1; i++)
                {

                    questions[s].datasheet.Cells[2, i] = (((questions[s].values[i - 2]) / total) * 100) + "%";

                }

            }
            else if (data_format == 3)
            {
                for (int i = 2; i <= choices_no1 + 1; i++)
                {
                    questions[s].datasheet.Cells[2, i] = questions[s].values[i - 2];
                    Graph.DataLabel label = ss.Item(1).DataLabels(i - 1);
                   label.Text = (((questions[s].values[i - 2]) / total) * 100).ToString() + "%" + "[" + questions[s].values[i - 2].ToString() + "]";

                }

                objShape2 = objShapes[4];
                objShape2.TextEffect.Text = "Total" + " " + total.ToString();

            }
        }
Exemple #21
0
        public void add_slide1(ref int question_no, ref List<question> questions, ref OpenFileDialog open)
        {
            objSlide = objPres.Slides[1];

            objslide1 = objPres.Slides[2];
               //objSlides.InsertFromFile("C:\\Users\\Ali\\Desktop\\Fastest Responders (in seconds).pptx", 0, 1, 1);
        }
Exemple #22
0
        public void add_slide( ref int question_no,ref List<question> questions,ref OpenFileDialog open)
        {
            if(questions[question_no].orien==false)
                objSlides.InsertFromFile("c:\\tmphor.ppt", question_no, 1, 1);
            else

            objSlides.InsertFromFile("c:\\tmp.ppt", question_no,1,1);
            objSlide = objSlides[question_no + 1];
            objSlide.FollowMasterBackground = MsoTriState.msoFalse;
            objSlide.Background.Fill.BackColor.RGB =ColorTranslator.ToOle( questions[question_no].background);
            if (questions[question_no].back_image != "")
            objSlide.Background.Fill.UserPicture(questions[question_no].back_image);
        }
Exemple #23
0
        private void examplePresentation()
        {
            String presentationTitle = "Proposta de Trabalho 3";

            //Add a new slide with Title Layout
            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitle);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = presentationTitle;
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Carlos Ribeiro 71945\nGisela Pinto 76397";

            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "PowerPoint";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Plataforma para apresentações mais profissionais.\n" +
                                              "Serve de guideline numa apresentação e também para partilhar informação acerca de um tema.\n" +
                                              "O objetivo do trabalho é facilitar ainda mais a sua utilização.";


            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Cenário";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "O Carlos e a Gisela estão no ínicio de uma apresentação numa conferência internacional e esqueceram-se do ponteiro para apresentar os slides.\n" +
                                              "A Gisela coloca-se em frente a um dispositivo e começa a sua apresentação de forma interativa.\n" +
                                              "O Carlos vai apresentando e mudando os slides.\n" +
                                              "A Gisela encontra-se a apresentar uma figura, e faz zoom para que o público consiga observar melhor.\n" +
                                              "No fim fecham a apresentação e tudo correu bem.";

            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Gestos escolhidos";
            tShape = oSlide.Shapes[2];
            tShape.TextFrame.TextRange.Text = "Avançar slide.\n" +
                                              "Recuar slide.\n" +
                                              "Crop da imagem.\n" +
                                              "Zoom de uma imagem.\n" +
                                              "Adicionar tema.\n" +
                                              "Abrir modo apresentação.\n" +
                                              "Fechar modo apresentação.";

            oSlide = oPresentation.Slides.Add(oPresentation.Slides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutText);
            tShape = oSlide.Shapes.Title;
            tShape.TextFrame.TextRange.Text = "Imagem";
            tShape = oSlide.Shapes[2];

            //Resize image
            OpenFileDialog open = new OpenFileDialog();

            string workingDirectory = Environment.CurrentDirectory;
            string parentDirectory  = Directory.GetParent(workingDirectory).Parent.FullName;

            open.FileName = parentDirectory + @"\kitty_cat.jpg";
            Console.WriteLine(open.FileName);
            FileInfo file        = new FileInfo(open.FileName);
            var      sizeInBytes = file.Length;

            Bitmap img = new Bitmap(open.FileName);

            var imageHeight = img.Height;
            var imageWidth  = img.Width;


            //to move image just modify left top from the function AddPicture
            tShape = oSlide.Shapes.AddPicture(open.FileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0, imageWidth, imageHeight);

            imgWidth  = tShape.Width;
            imgHeight = tShape.Height;
        }
Exemple #24
0
 /// <summary>
 /// Adds a new slide to presentation.
 /// </summary>
 public void AddSlide()
 {
     oCount   = 1;
     objSlide = objSlides.Add(sCount++, PowerPoint.PpSlideLayout.ppLayoutBlank);
 }
        public static void IncludeOthers(string path)
        {
            //Build Slide #2:
            //Add text to the slide title, format the text. Also add a chart to the
            //slide and change the chart type to a 3D pie chart.
            objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
            objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
            objTextRng.Text = "My Chart";
            objTextRng.Font.Name = "Comic Sans MS";
            objTextRng.Font.Size = 48;
            objChart = (Graph.Chart)objSlide.Shapes.AddOLEObject(150, 150, 480, 320,
              "MSGraph.Chart.8", "", MsoTriState.msoFalse, "", 0, "",
              MsoTriState.msoFalse).OLEFormat.Object;
            objChart.ChartType = Graph.XlChartType.xl3DPie;
            objChart.Legend.Position = Graph.XlLegendPosition.xlLegendPositionBottom;
            objChart.HasTitle = true;
            objChart.ChartTitle.Text = "Here it is...";

            //Build Slide #3:
            //Change the background color of this slide only. Add a text effect to the slide
            //and apply various color schemes and shadows to the text effect.
            objSlide = objSlides.Add(objSlides.Count + 1, PowerPoint.PpSlideLayout.ppLayoutBlank);
            objSlide.FollowMasterBackground = MsoTriState.msoFalse;
            objShapes = objSlide.Shapes;
            objShape = objShapes.AddTextEffect(MsoPresetTextEffect.msoTextEffect27,
              "The End", "Impact", 96, MsoTriState.msoFalse, MsoTriState.msoFalse, 230, 200);

            //Save the presentation to disk
            objPres.SaveAs(path,
                  PowerPoint.PpSaveAsFileType.ppSaveAsPresentation,
                  Microsoft.Office.Core.MsoTriState.msoFalse);
            //Modify the slide show transition settings for all 3 slides in
            //the presentation.
            int[] SlideIdx = new int[3];
            for (int k = 0; k < 3; k++) SlideIdx[k] = k + 1;
            objSldRng = objSlides.Range(SlideIdx);
            objSST = objSldRng.SlideShowTransition;
            objSST.AdvanceOnTime = MsoTriState.msoTrue;
            objSST.AdvanceTime = 3;
            objSST.EntryEffect = PowerPoint.PpEntryEffect.ppEffectBoxOut;

            //Prevent Office Assistant from displaying alert messages:
            // bAssistantOn = objApp.Assistant.On;
            // objApp.Assistant.On = false;

            //Run the Slide show from slides 1 thru 3.
            objSSS = objPres.SlideShowSettings;
            objSSS.StartingSlide = 1;
            objSSS.EndingSlide = 3;
            objSSS.Run();

            //Wait for the slide show to end.
            objSSWs = objApp.SlideShowWindows;
            while (objSSWs.Count >= 1) System.Threading.Thread.Sleep(100);

            ////Reenable Office Assisant, if it was on:
            //if (bAssistantOn)
            //{
            //    objApp.Assistant.On = true;
            //    objApp.Assistant.Visible = false;
            //}

            //Close the presentation without saving changes and quit PowerPoint.
            //  objPres.Close();
            //  objApp.Quit();
        }
Exemple #26
0
 private void OnWindowSelectionChanged(Selection Sel)
 {
     if (Sel != null)
     {
         try
         {
             PowerPoint.PpSelectionType type = Sel.Type;
             if (type == PowerPoint.PpSelectionType.ppSelectionShapes)
             {
                 selectedShapePositions = new List <int>(0);
                 PowerPoint.ShapeRange range = Sel.ShapeRange;
                 if (range == null)
                 {
                     return;
                 }
                 foreach (PowerPoint.Shape shape in range)
                 {
                     selectedShapePositions.Add(shape.Id);
                 }
             }
             else if (type == PowerPoint.PpSelectionType.ppSelectionNone)
             {
                 if (selectedShapePositions != null && selectedShapePositions.Count > 0)
                 {
                     PowerPoint._Slide slide = GetActiveSlide();
                     if (slide == null)
                     {
                         return;
                     }
                     foreach (int position in selectedShapePositions)
                     {
                         PowerPoint.Shape shape = getShape(slide.SlideIndex, position);
                         if (shape != null)
                         {
                             continue;
                         }
                         if (ShapeDeleted != null)
                         {
                             ShapeDeleted(slide.SlideNumber, slide.Name, position, "", SlideItemType.NULL, "");
                         }
                     }
                     selectedShapePositions = new List <int>(0);
                 }
             }
         }
         catch
         {
             //PowerPoint._Slide slide = GetActiveSlide();
             //if (slide == null) return;
             //foreach (int position in selectedShapePositions)
             //{
             //    if (ShapeDeleted != null) ShapeDeleted(slide.SlideNumber, slide.Name, position, "", SlideItemType.NULL, "");
             //}
             selectedShapePositions = new List <int>(0);
         }
     }
     else
     {
         selectedShapePositions = new List <int>(0);
     }
 }
Exemple #27
0
        /// <summary>
        /// Create a slide model from a powerpoint slide
        /// </summary>
        /// <param name="pageSetup"></param>
        /// <param name="pptpm"></param>
        /// <param name="deck"></param>
        /// <param name="tempFileCollection"></param>
        /// <param name="dirpath"></param>
        /// <param name="currentSlide"></param>
        /// <returns></returns>
        private static SlideModel CreateSlide(PowerPoint.PageSetup pageSetup, PPTPaneManagement.PPTPaneManager pptpm, DeckModel deck, TempFileCollection tempFileCollection, string dirpath, PowerPoint._Slide currentSlide)
        {
            int   slideWidth  = (int)pageSetup.SlideWidth;  //Standard = 720  => 6000
            int   slideHeight = (int)pageSetup.SlideHeight; //Standard = 540  => 4500
            float emfWidth    = slideWidth * 25 / 3;
            float emfHeight   = slideHeight * 25 / 3;

            PowerPoint.Shapes currentShapes = currentSlide.Shapes;

            List <TaggedShape> taggedShapeList = PPTDeckIO.BuildTaggedShapeList(currentShapes, pptpm);

            //Create a new SlideModel
            SlideModel newSlideModel = new SlideModel(Guid.NewGuid(), new LocalId(), SlideDisposition.Empty, new Rectangle(0, 0, slideWidth, slideHeight));

            //Lock it
            using (Synchronizer.Lock(newSlideModel.SyncRoot)) {
                //Set the slide's title
                newSlideModel.Title = PPTDeckIO.FindSlideTitle(taggedShapeList);

                PPTDeckIO.MakeShapesInvisible(currentShapes);

                //Create the Background image
                //Generate a new filename
                string filename   = PPTDeckIO.GenerateFilename();
                bool   bitmapMode = true;
                if (bitmapMode)
                {
                    filename = dirpath + "\\" + filename + ".JPG";
                    currentSlide.Export(filename, "JPG", 0, 0);

                    // Need to also export as EMF to get the size of the slide in inches
                    currentSlide.Export(filename + "_TEMP", "EMF", 0, 0);
                    tempFileCollection.AddFile(filename + "_TEMP", false);
                }
                else
                {
                    filename = dirpath + "\\" + filename + ".emf";
                    currentSlide.Export(filename, "EMF", 0, 0);
                }
                tempFileCollection.AddFile(filename, false);

                //Compute the MD5 of the BG
                FileStream fs          = new FileStream(filename, FileMode.Open, FileAccess.Read);
                MD5        md5Provider = new MD5CryptoServiceProvider();
                byte[]     md5         = md5Provider.ComputeHash(fs);
                fs.Seek(0, SeekOrigin.Begin);
                Image image = Image.FromStream(fs);
                if (bitmapMode)
                {
                    image = DisassociateBitmap(image);
                }
                fs.Close();

                // Open the EMF version if we used a bitmap to get the conversion
                if (bitmapMode)
                {
                    FileStream fsEMF     = new FileStream(filename + "_TEMP", FileMode.Open, FileAccess.Read);
                    Image      image_emf = Image.FromStream(fsEMF);
                    emfWidth  = image_emf.Width;
                    emfHeight = image_emf.Height;
                    fsEMF.Close();
                    image_emf.Dispose();
                }
                else
                {
                    emfWidth  = image.Width;
                    emfHeight = image.Height;
                }

                //Create the ImageSheet
                ImageSheetModel sheet = new ImageSheetModel(deck, Guid.NewGuid(), Model.Presentation.SheetDisposition.Background,
                                                            new Rectangle(0, 0, slideWidth, slideHeight), (ByteArray)md5, 1);
                //Add the ImageSheet to the Slide
                newSlideModel.ContentSheets.Add(sheet);
                //Add the Image+MD5 to the deck
                deck.AddSlideContent((ByteArray)md5, image);

                // Restore visibility - this makes everything visible - a bug?
                PPTDeckIO.MakeShapesVisible(currentShapes);

                List <List <TaggedShape> > layerList = PPTDeckIO.SeparateIntoLayers(taggedShapeList);

                int startHeight = 2;
                foreach (List <TaggedShape> layer in layerList)
                {
                    PPTDeckIO.ProcessLayer(layer, tempFileCollection, currentShapes, deck, newSlideModel,
                                           slideWidth / emfWidth, slideHeight / emfHeight, startHeight++);
                }

                //Add SlideModel to the deck
                deck.InsertSlide(newSlideModel);
            }
            return(newSlideModel);
        }
Exemple #28
0
        private void ReadTextAndImagesToMakePPT(string author, string comment, int likes, int slideNumber)
        {
            string pictureFileName = SelectImageDelegate(slideNumber - 1);

            if (this.isNewPresentation)
            {
                this.isNewPresentation = false;
                this.pptApplication    = new Microsoft.Office.Interop.PowerPoint.Application();
                // Create the Presentation File
                this.pptPresentation = this.pptApplication.Presentations.Add(MsoTriState.msoTrue);

                textBoxLocationArray[0] = new List <float> {
                    20, 20
                };
                textBoxLocationArray[1] = new List <float> {
                    this.pptPresentation.PageSetup.SlideWidth / 2 - Constants.textBox1Width / 2, 20
                };
                textBoxLocationArray[2] = new List <float> {
                    this.pptPresentation.PageSetup.SlideWidth - (Constants.textBox1Width + 20), 20
                };
            }

            Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout =
                this.pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

            // Create new Slide
            this.slides = this.pptPresentation.Slides;

            this.slide = this.slides.AddSlide(1, customLayout);
            // slide.TimeLine.InteractiveSequences.

            this.slide.Layout = PpSlideLayout.ppLayoutBlank;

            // Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
            var picShape = this.slide.Shapes.AddPicture(pictureFileName,
                                                        Microsoft.Office.Core.MsoTriState.msoFalse,
                                                        Microsoft.Office.Core.MsoTriState.msoTrue, 0, 0,
                                                        this.pptPresentation.PageSetup.SlideWidth,
                                                        this.pptPresentation.PageSetup.SlideHeight);

            // picShape.AnimationSettings.AnimateBackground = MsoTriState.msoCTrue;

            SelectTextBoxLocation(pictureFileName);

            for (int i = 1; i < 2; i++)
            {
                CreateTextBoxesAndSetProperties(author, comment, likes, i);
            }

            if (this.isLastSlide)
            {
                var sh = this.slide.Shapes.AddMediaObject2(soundFilePath, MsoTriState.msoFalse,
                                                           MsoTriState.msoTrue, 250, 10);


                sh.AnimationSettings.PlaySettings.PlayOnEntry         = MsoTriState.msoTrue;
                sh.AnimationSettings.PlaySettings.HideWhileNotPlaying = MsoTriState.msoTrue;
                // sh.AnimationSettings.PlaySettings.PauseAnimation = MsoTriState.msoFalse;

                sh.AnimationSettings.PlaySettings.StopAfterSlides  = 999;
                sh.AnimationSettings.PlaySettings.LoopUntilStopped = MsoTriState.msoCTrue;

                sh.Name = "musicBackground";
                // sh.MediaFormat.Volume = 0.1f;
            }

            if (embeddedSpeechSupport)
            {
                var she = this.slide.Shapes.AddMediaObject2($"E:\\PowerPoint\\Read\\{slideNumber}.mp3", MsoTriState.msoFalse,
                                                            MsoTriState.msoTrue, 350, 10);


                she.AnimationSettings.PlaySettings.PlayOnEntry         = MsoTriState.msoTrue;
                she.AnimationSettings.PlaySettings.HideWhileNotPlaying = MsoTriState.msoTrue;
                // sh.AnimationSettings.PlaySettings.PauseAnimation = MsoTriState.msoFalse;

                she.AnimationSettings.PlaySettings.StopAfterSlides = 1;
            }
            picShape.AnimationSettings.AnimateBackground = MsoTriState.msoCTrue;

            this.pptPresentation.SaveAs(Constants.pptTestFile,
                                        Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
                                        MsoTriState.msoTrue);
        }
Exemple #29
0
        //TODO: Image type needs to be more dynamically chosen...
        public static DeckModel OpenPPT(FileInfo file, BackgroundWorker worker, DoWorkEventArgs progress)
        {
            //Start the progress bar
            if (worker != null)
            {
                worker.ReportProgress(0, "Initializing...");
            }

            //Make the default flat tree representation of the PPT
            //Try to detect if powerpoint is already running (powerpnt.exe)
            bool pptAlreadyRunning = false;

            Process[] processes = Process.GetProcesses();
            for (int i = 0; i < processes.Length; i++)
            {
                string currentProcess = processes[i].ProcessName.ToLower();
                if (currentProcess == "powerpnt")
                {
                    pptAlreadyRunning = true;
                    break;
                }
            }
            //Open PowerPoint + open file
            PowerPoint.Application pptapp;
            try {
                pptapp = new PowerPoint.Application();
            }
            catch (Exception e) {
                throw new PPTNotInstalledException("Failed to create PowerPoint Application.  See InnerException for details.", e);
            }

            PowerPoint._Presentation presentation;
            try {
                presentation = pptapp.Presentations.Open(file.FullName, Core.MsoTriState.msoTrue, Core.MsoTriState.msoFalse, Core.MsoTriState.msoFalse);
            }
            catch (Exception e) {
                throw new PPTFileOpenException("Failed to open PowerPoint file.  See InnerException for details.", e);
            }

            //Initialize the PPT Shape tag reader
            PPTPaneManagement.PPTPaneManager pptpm = new PPTPaneManagement.PPTPaneManager();
            //Create a new DeckModel

            DeckModel deck = new DeckModel(Guid.NewGuid(), DeckDisposition.Empty, file.Name);

            //Initialize a temporary file collection that will be where slide images are exported to
            TempFileCollection tempFileCollection = new TempFileCollection();
            string             dirpath            = tempFileCollection.BasePath;

            if (!Directory.Exists(dirpath))
            {
                Directory.CreateDirectory(dirpath);
            }
            else
            {
                Directory.Delete(dirpath, true);
                Directory.CreateDirectory(dirpath);
            }

            //Lock it
            using (Synchronizer.Lock(deck.SyncRoot)) {
                //Iterate over all slides
                for (int i = 1; i <= presentation.Slides.Count; i++)
                {
                    if (progress != null && progress.Cancel)
                    {
                        break;
                    }

                    //Get the slide
                    PowerPoint._Slide currentSlide = presentation.Slides[i];



                    SlideModel newSlideModel = CreateSlide(presentation.PageSetup, pptpm, deck, tempFileCollection, dirpath, currentSlide);

                    //Create a new Entry + reference SlideModel
                    TableOfContentsModel.Entry newEntry = new TableOfContentsModel.Entry(Guid.NewGuid(), deck.TableOfContents, newSlideModel);
                    //Lock the TOC
                    using (Synchronizer.Lock(deck.TableOfContents.SyncRoot)) {
                        //Add Entry to TOC
                        deck.TableOfContents.Entries.Add(newEntry);
                    }
                    //Increment the ProgressBarForm
                    if (worker != null)
                    {
                        worker.ReportProgress((i * 100) / presentation.Slides.Count, "Reading slide " + i + " of " + presentation.Slides.Count);
                    }
                }
            }
            //Close the presentation
            presentation.Close();
            presentation = null;
            //If PowerPoint was not open before, close PowerPoint
            if (!pptAlreadyRunning)
            {
                pptapp.Quit();
                pptapp = null;
            }
            GC.Collect();
            //Delete temp directory
            tempFileCollection.Delete();
            Directory.Delete(dirpath);

            if (worker != null)
            {
                worker.ReportProgress(100, "Done!");
            }

            //Return the deck
            if (progress != null)
            {
                progress.Result = deck;
            }
            return(deck);
        }
 public static void IncludeImage(string path)
 {
     //Build Slide #1:
     //Add text to the slide, change the font and insert/position a
     //picture on the first slide.
     objSlide = objSlides.Add(objSlides.Count+1, PowerPoint.PpSlideLayout.ppLayoutTitleOnly);
     objTextRng = objSlide.Shapes[1].TextFrame.TextRange;
     objTextRng.Text = "Summary Report";
     objTextRng.Font.Name = "Comic Sans MS";
     objTextRng.Font.Size = 48;
     objSlide.Shapes.AddPicture(path, MsoTriState.msoFalse, MsoTriState.msoTrue,
       0, 50, 700, 450);
 }
        /// <summary>
        /// Open a PPT deck and create a directory of jpg images, one for each slide in the deck.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="file"></param>
        private void processPpt(Guid g, FileInfo file)
        {
            if (stopNow)
            {
                return;
            }

            if (pptApp == null)
            {
                try {
                    pptApp = new PowerPoint.Application();
                    // Check if PPT was already running.
                    pptAlreadyOpen = (pptApp.Visible == MsoTriState.msoTrue);
                }
                catch (Exception e) {
                    log.WriteLine("Failed to create PowerPoint application instance. " + e.ToString());
                    log.ErrorLevel = 6;
                    pptApp         = null;
                    return;
                }
            }

            try {
                PowerPoint._Presentation ppPres = pptApp.Presentations.Open(file.FullName, MsoTriState.msoTrue,
                                                                            MsoTriState.msoFalse, MsoTriState.msoFalse);

                PowerPoint.Slides slides = ppPres.Slides;

                String tempDirName = Utility.GetTempDir();
                Directory.CreateDirectory(tempDirName);
                int slideCount = slides.Count;
                int ptStart    = progressTracker.CurrentValue;
                for (int i = 1; i <= slides.Count; i++)
                {
                    if (stopNow)
                    {
                        break;
                    }
                    //The image looks much better and is reasonably small if we save to wmf format first, then
                    // convert to jpg.  I guess the .Net jpeg encoder is better than the PPT encoder??
                    // Sometimes we may want to use the jpeg export with certain decks because we can get better
                    // fidelity with some less common symbols.

                    PowerPoint._Slide ppSlide = (PowerPoint._Slide)slides._Index(i);
                    String            jpgfile = Path.Combine(tempDirName, "slide" + i.ToString() + ".jpg");
                    Image             img     = null;
                    string            tmpfile = null;
                    if (useNativeJpegExport)
                    {
                        tmpfile = Path.Combine(tempDirName, "slidetmp" + i.ToString() + ".JPG");
                        ppSlide.Export(tmpfile, "JPG", 0, 0);
                        img = Image.FromFile(tmpfile);
                    }
                    else
                    {
                        tmpfile = Path.Combine(tempDirName, "slide" + i.ToString() + ".WMF");
                        ppSlide.Export(tmpfile, "WMF", 0, 0);
                        img = Image.FromFile(tmpfile);
                    }
                    try {
                        //The right shift is used to work around a CP3 issue: Some slide decks are shifted to the right, so we also
                        // need to do this to keep ink from being mis-aligned.  As of 2013 this should no longer be needed when
                        // using a current version of CP3.
                        if (rightShift > 0)
                        {
                            Image shiftedImage;
                            RightImageShift(img, rightShift, out shiftedImage);
                            shiftedImage.Save(jpgfile, ImageFormat.Jpeg);
                            shiftedImage.Dispose();
                        }
                        else
                        {
                            img.Save(jpgfile, ImageFormat.Jpeg);
                        }
                    }
                    catch (Exception e) {
                        log.WriteLine("Failed to save image for slide " + jpgfile + " exception: " + e.ToString());
                        log.ErrorLevel = 6;
                    }
                    img.Dispose();
                    System.IO.File.Delete(tmpfile);

                    progressTracker.CurrentValue = ((i * 100) / slideCount) + ptStart;
                }

                ppPres.Close();
                ppPres = null;

                this.outputDirs.Add(g, tempDirName);
            }
            catch (Exception e) {
                log.WriteLine(e.ToString());
                log.ErrorLevel = 6;
            }
        }