Exemplo n.º 1
0
        protected void ClearObject()
        {
            if (this.PptPresentation != null)
            {
                if (this.IsPresentationOpened)
                {
                    this.PptPresentation.Close();
                    this.IsPresentationOpened = false;
                }

                ReleaseObj.Marshal.ReleaseComObject(PptPresentation);
                this.PptPresentation = null;
            }


            if (this.PptApplication != null)
            {
                if (this.IsAppOpened)
                {
                    this.PptApplication.Quit();
                    this.IsAppOpened = false;
                }

                ReleaseObj.Marshal.ReleaseComObject(PptApplication);
                this.PptApplication = null;
            }

            this.ClearnGarbage();
        }
Exemplo n.º 2
0
 public void Test_pptx_CWD_Sheet()
 {
     String[] args = { $"{PREFIX}{cwd}\\test Slides.pptx#2" };
     Program.Main(args);
     PowerPoint._Application ppt = Program.GetPowerPoint();
     Assert.AreEqual(2, ppt.ActiveWindow.View.Slide.slideIndex);
     ppt.ActivePresentation.Close();
 }
Exemplo n.º 3
0
 public void Test_pptx_CWD_PageNoParseError()
 {
     StartCaptureMessage(UrlHandler.Program.TITLE);
     String[] args = { $"{PREFIX}{cwd}\\test Slides.pptx#Noname" };
     Program.Main(args);
     PowerPoint._Application ppt = Program.GetPowerPoint();
     Assert.AreEqual("Slide number Noname is not a number.", StopCaptureMessage());
     ppt.ActivePresentation.Close();
 }
Exemplo n.º 4
0
 public void Test_pptx_CWD_WrongSheet()
 {
     StartCaptureMessage(UrlHandler.Program.TITLE);
     String[] args = { $"{PREFIX}{cwd}\\test Slides.pptx#5" };
     Program.Main(args);
     PowerPoint._Application ppt = Program.GetPowerPoint();
     Assert.AreEqual("Slide number 5 is out of range. the presentation has only 3 slide[s].", StopCaptureMessage());
     ppt.ActivePresentation.Close();
 }
Exemplo n.º 5
0
 public void EndPresentation()
 {
     if (pPre != null && pPre.SlideShowWindow.View.CurrentShowPosition > 1)
     {
         pPre.SlideShowWindow.View.EndNamedShow();
         pPre.Close();
         pApp.Quit();
         pApp = null;
         pPre = null;
     }
 }
Exemplo n.º 6
0
 public void Test_pptx_CWD_Sheet_WrongObjects()
 {
     StartCaptureMessage(UrlHandler.Program.TITLE);
     String[] args = { $"{PREFIX}{cwd}\\test Slides.pptx#2!Rectangle 3" };
     Program.Main(args);
     PowerPoint._Application ppt = Program.GetPowerPoint();
     Assert.AreEqual(2, ppt.ActiveWindow.View.Slide.slideIndex);
     PowerPoint.Selection actual = ppt.ActiveWindow.Selection;
     Assert.AreEqual("Object \"Rectangle 3\" not found", StopCaptureMessage());
     ppt.ActivePresentation.Close();
 }
Exemplo n.º 7
0
 public void Test_pptx_CWD_Sheet_Objects()
 {
     String[] args = { $"{PREFIX}{cwd}\\test Slides.pptx#2!Rounded Rectangle 4,Rounded Rectangle 5" };
     Program.Main(args);
     PowerPoint._Application ppt = Program.GetPowerPoint();
     Assert.AreEqual(2, ppt.ActiveWindow.View.Slide.slideIndex);
     PowerPoint.Selection actual = ppt.ActiveWindow.Selection;
     Assert.AreEqual("Rounded Rectangle 4", actual.ShapeRange[1].Name);
     Assert.AreEqual("Rounded Rectangle 5", actual.ShapeRange[2].Name);
     ppt.ActivePresentation.Close();
 }
Exemplo n.º 8
0
        public MainWindow()
        {
            InitializeComponent();


            mmiC          = new MmiCommunication("localhost", 8000, "User1", "GUI");
            mmiC.Message += MmiC_Message;
            mmiC.Start();
            oPowerPoint   = new PowerPoint.Application();
            oPresentation = oPowerPoint.Presentations.Add();
            examplePresentation();
            openpowerpoint   = true;
            presentationMode = false;
        }
Exemplo n.º 9
0
        public void StartPresentation()
        {
            string presExisting = @"D:/Sample_DryRun_Collections.pptx";

            if (pApp == null && pPre == null)
            {
                pApp = new PowerPoint.Application();

                pPre = pApp.Presentations.Open(
                    presExisting, Office.MsoTriState.msoFalse,
                    Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue
                    );
                //Start playing presentation.
                pPre.SlideShowSettings.Run();
            }
        }
Exemplo n.º 10
0
        public void StartPresentation()
        {
            string presExisting = @"D:/Health_Environment_Cancer_v0.1.pptx";

            if (pApp == null && pPre == null)
            {
                pApp = new PowerPoint.Application();

                pPre = pApp.Presentations.Open(
                    presExisting, Office.MsoTriState.msoFalse,
                    Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue
                    );
                //Start playing presentation.
                pPre.SlideShowSettings.Run();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Opens the <paramref name="inputFile"/> and returns it as an <see cref="PowerPointInterop.Presentation"/> object
        /// </summary>
        /// <param name="powerPoint">The <see cref="PowerPointInterop.Application"/></param>
        /// <param name="inputFile">The file to open</param>
        /// <param name="repairMode">When true the <paramref name="inputFile"/> is opened in repair mode</param>
        /// <returns></returns>
        /// <exception cref="OCFileIsCorrupt">Raised when the <paramref name="inputFile"/> is corrupt and can't be opened in repair mode</exception>
        private static PowerPointInterop.Presentation Open(PowerPointInterop._Application powerPoint, string inputFile, bool repairMode)
        {
            try
            {
                return(powerPoint.Presentations.Open(inputFile, MsoTriState.msoTrue, MsoTriState.msoTrue,
                                                     MsoTriState.msoFalse));
            }
            catch (Exception exception)
            {
                if (repairMode)
                {
                    throw new OCFileIsCorrupt("The file '" + Path.GetFileName(inputFile) +
                                              "' seems to be corrupt, error: " +
                                              ExceptionHelpers.GetInnerException(exception));
                }

                return(Open(powerPoint, inputFile, true));
            }
        }
Exemplo n.º 12
0
        public static void ConvertirPowerPoint(string nombrearchivo)
        {
            string logFile = BusinessVariables.Directorios.RepositorioRepositorio + @"LogArchivosWord.txt";

            if (!File.Exists(logFile))
            {
                // Create a file to write to.
                using (StreamWriter sw = File.CreateText(logFile))
                {
                    sw.WriteLine("Inicio Log" + DateTime.Now.ToString());
                }
            }
            PowerPoint._Application winWord = null;
            using (StreamWriter file = new StreamWriter(logFile))
            {
                try
                {
                    file.WriteLine("Inicia Proceso");
                    string htmlFilePath = BusinessVariables.Directorios.RepositorioInformacionConsultaHtml + Path.GetFileNameWithoutExtension(nombrearchivo) + ".htm";
                    string fileName     = BusinessVariables.Directorios.RepositorioInformacionConsulta + nombrearchivo;

                    PowerPoint.Application ppApp = new PowerPoint.Application();
                    ppApp.Visible = MsoTriState.msoTrue;
                    PowerPoint.Presentations ppPresens = ppApp.Presentations;
                    PowerPoint.Presentation  objPres   = ppPresens.Open(fileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
                    file.WriteLine("Abrio Presentacion");
                    file.WriteLine("Guardara Nueva Presentacion nuevo formato");
                    file.WriteLine(htmlFilePath);
                    objPres.SaveAs(htmlFilePath, PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoCTrue);
                    file.WriteLine("Guardo nuevo formato");
                    PowerPoint.Slides objSlides = objPres.Slides;
                    //PowerPoint.SlideShowWindows objSSWs;
                    //PowerPoint.SlideShowSettings objSSS;
                    ////Run the Slide show
                    //objSSS = objPres.SlideShowSettings;
                    //objSSS.Run();
                    //objSSWs = ppApp.SlideShowWindows;
                    //while (objSSWs.Count >= 1)
                    //    System.Threading.Thread.Sleep(100);
                    ////Close the presentation without saving changes and quit PowerPoint
                    //objPres.Close();
                    ppApp.Quit();



                    //file.WriteLine("Inicia aplicacion");
                    //winWord = new PowerPoint.ApplicationClass();
                    //file.WriteLine("Abre Archivo");
                    //PowerPoint.Presentation prsPres = winWord.Presentations.Open(fileName, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                    //file.WriteLine("Abrio Archivo");
                    //file.WriteLine(htmlFilePath);
                    //file.WriteLine("GuardaraNuevo Documento nuevo formato");
                    //prsPres.SaveAs(htmlFilePath, PowerPoint.PpSaveAsFileType.ppSaveAsHTML);
                    //file.WriteLine("Guardo nuevo formato");
                    //prsPres.Close();
                    //file.WriteLine("cerro documento");
                    //winWord.Quit();
                    //file.WriteLine("Cerro Word");
                }
                catch (Exception e)
                {
                    if (winWord != null)
                    {
                        winWord.Quit();
                    }
                    throw new Exception(e.Message);
                }
                finally
                {
                    GC.Collect();
                }
            }
        }
Exemplo n.º 13
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);

            //json.recognized
            Console.WriteLine(json);
            Console.WriteLine("0: ");
            Console.WriteLine(json.recognized[0].ToString());
            Console.WriteLine("1: ");
            Console.WriteLine(json.recognized[1].ToString());



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

                oPowerPoint   = new PowerPoint.Application();
                oPresentation = oPowerPoint.Presentations.Add();
                examplePresentation();
                openpowerpoint   = true;
                presentationMode = false;
                break;

            case "slide":
                switch ((string)json.recognized[1].ToString())
                {
                case "NEXT":
                    oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                    break;

                case "NEXT_PRESENTATION":
                    oPresentation.SlideShowWindow.View.Next();
                    break;

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

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

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

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

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

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

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

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

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

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

            case "1":
                switch ((string)json.recognized[1].ToString())
                {
                case "CropI":
                    Console.WriteLine("DO CROP IN!");
                    SendMsg_Tts("Crop In encontra-se ativo.", "speak");
                    tShape.PictureFormat.CropLeft   = imgWidth * 20 / 100;
                    tShape.PictureFormat.CropRight  = imgWidth * 20 / 100;
                    tShape.PictureFormat.CropBottom = imgHeight * 20 / 100;
                    tShape.PictureFormat.CropTop    = imgHeight * 20 / 100;

                    break;
                }
                break;

            case "2":
                switch ((string)json.recognized[1].ToString())
                {
                case "CropO":
                    Console.WriteLine("DO CROP OUT!");
                    //crop Picture
                    SendMsg_Tts("Crop Out encontra-se ativo.", "speak");
                    tShape.PictureFormat.CropLeft   = imgWidth * (20 / 100);
                    tShape.PictureFormat.CropRight  = imgWidth * (20 / 100);
                    tShape.PictureFormat.CropBottom = imgHeight * (20 / 100);
                    tShape.PictureFormat.CropTop    = imgHeight * (20 / 100);

                    break;
                }
                break;

            case "3":
                switch ((string)json.recognized[1].ToString())
                {
                case "NextR":
                    if (presentationMode == true)
                    {
                        oPresentation.SlideShowWindow.View.Next();
                    }
                    else
                    {
                        oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex + 1].Select();
                    }
                    break;
                }
                break;

            case "5":
                switch ((string)json.recognized[1].ToString())
                {
                case "PreviouL":
                    Console.WriteLine("DO PREVIOUS!");
                    if (presentationMode == true)
                    {
                        oPresentation.SlideShowWindow.View.Previous();
                    }
                    else
                    {
                        oPresentation.Slides[oPowerPoint.ActiveWindow.Selection.SlideRange.SlideIndex - 1].Select();
                    }
                    break;
                }
                break;

            case "6":
                switch ((string)json.recognized[1].ToString())
                {
                case "ThemaR":
                    switch ((string)json.recognized[3].ToString())
                    {
                    case "1":
                        SendMsg_Tts("Tema 1 encontra-se ativo.", "speak");

                        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":
                        SendMsg_Tts("Tema 2 encontra-se ativo.", "speak");

                        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":
                        SendMsg_Tts("Tema 3 encontra-se ativo.", "speak");

                        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;
                }
                break;

            case "7":
                switch ((string)json.recognized[1].ToString())
                {
                case "ZoomI":
                    Console.WriteLine("DO ZOOM IN!");
                    SendMsg_Tts("O modo Zoom In encontra-se ativo.", "speak");
                    tShape.ScaleHeight(1.2f, Microsoft.Office.Core.MsoTriState.msoFalse);
                    tShape.ScaleWidth(1.2f, Microsoft.Office.Core.MsoTriState.msoFalse);


                    break;
                }
                break;


            case "8":
                switch ((string)json.recognized[1].ToString())
                {
                case "ZoomO":
                    SendMsg_Tts("O modo Zoom Out encontra-se ativo.", "speak");
                    Console.WriteLine("DO ZOOM OUT!");
                    tShape.ScaleHeight(0.8f, Microsoft.Office.Core.MsoTriState.msoFalse);
                    tShape.ScaleWidth(0.8f, Microsoft.Office.Core.MsoTriState.msoFalse);

                    break;
                }
                break;


            case "4":
                switch ((string)json.recognized[1].ToString())
                {
                case "Open":

                    Console.WriteLine("OPEN Presentation Mode!");
                    oPresentation.SlideShowSettings.Run();
                    presentationMode = true;
                    SendMsg_Tts("open presentation grammer", "presentation");
                    SendMsg_Tts("O modo apresentação encontra-se ativo.", "speak");
                    break;
                }
                break;

            case "0":
                switch ((string)json.recognized[1].ToString())
                {
                case "Close":
                    Console.WriteLine("DO CLOSE!");
                    oPresentation.SlideShowWindow.View.Exit();
                    presentationMode = false;
                    SendMsg_Tts("change to edition grammer", "stop_presentation");
                    SendMsg_Tts("O modo apresentação foi desativado.", "speak");
                    break;
                }
                break;

            case "presentation":
                switch ((string)json.recognized[0].ToString())
                {
                case "START":
                    SendMsg_Tts("O modo apresentação foi ativado.", "speak");
                    oPresentation.SlideShowSettings.Run();
                    break;

                case "STOP_PRESENTATION":
                    SendMsg_Tts("O modo apresentação foi ativado.", "speak");
                    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();
                    }
                }
                presentationMode = false;
                SendMsg_Tts("Power Point foi fechado", "speak");

                break;
            }
        }
Exemplo n.º 14
0
        public void OnStartupComplete(ref System.Array custom)
        {
            CommandBars oCommandBars;
            CommandBar oStandardBar;

            object omissing = System.Reflection.Missing.Value;

            Thread.Sleep(50);
            //Console.Beep(3000, 20);

            app = (Microsoft.Office.Interop.PowerPoint._Application)applicationObject;

            try
            {
                oCommandBars = (CommandBars)applicationObject.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, applicationObject, null);
            }
            catch (Exception)
            {
                //// Outlook has the CommandBars collection on the Explorer object.
                //object oActiveExplorer;
                //oActiveExplorer = applicationObject.GetType().InvokeMember("ActiveExplorer", BindingFlags.GetProperty, null, applicationObject, null);
                //oCommandBars = (CommandBars)oActiveExplorer.GetType().InvokeMember("CommandBars", BindingFlags.GetProperty, null, oActiveExplorer, null);
                return;
            }

            // Set up a custom button on the "Standard" commandbar.
            try
            {
                oStandardBar = oCommandBars["Menu Bar"];
            }
            catch (Exception)
            {
                // Access names its main toolbar Database.
                oStandardBar = oCommandBars["Database"];
            }

            CommandBarControls controls = oStandardBar.Controls;

            // remove old menus...
            foreach (CommandBarControl control in controls)
            {
                String caption = control.Caption;

                if (caption.EndsWith("Remote Documents") || caption.EndsWith("Remote documents"))
                {
                    control.Delete(null);
                }
            }

            // In case the button was not deleted, use the exiting one.
            try
            {
                eXoMenu = (CommandBarPopup)oStandardBar.Controls["Remote documents"];
                Open = (CommandBarButton)eXoMenu.Controls["Open"];
                Save = (CommandBarButton)eXoMenu.Controls["Save"];
                SaveAs = (CommandBarButton)eXoMenu.Controls["SaveAs"];
                //CompareWithBase = (CommandBarButton)eXoMenu.Controls["Compare with base"];
                Search = (CommandBarButton)eXoMenu.Controls["Search"];
                Settings = (CommandBarButton)eXoMenu.Controls["Settings"];
                About = (CommandBarButton)eXoMenu.Controls["About"];

            }

            catch (Exception)
            {
                eXoMenu = (CommandBarPopup)oStandardBar.Controls.Add(MsoControlType.msoControlPopup, omissing, omissing, omissing, true);
                eXoMenu.Caption = "Remote Documents";
                eXoMenu.Tag = eXoMenu.Caption;

                Open = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                Open.Caption = "Open...";
                Open.Tag = Open.Caption;

                Save = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                Save.Caption = "Save";
                Save.Tag = Save.Caption;

                SaveAs = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                SaveAs.Caption = "Save As...";
                SaveAs.Tag = SaveAs.Caption;

                //CompareWithBase = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                //CompareWithBase.Caption = "Compare with base";
                //CompareWithBase.Tag = CompareWithBase.Caption;
                //CompareWithBase.BeginGroup = true;

                Search = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                Search.Caption = "Search...";
                Search.Tag = Search.Caption;

                Settings = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                Settings.Caption = "Settings...";
                Settings.Tag = Settings.Caption;

                About = (CommandBarButton)eXoMenu.Controls.Add(1, omissing, omissing, omissing, omissing);
                About.Caption = "About...";
                About.Tag = About.Caption;
            }
            Open.Visible = true;
            Open.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Open_Click);

            Save.Visible = true;
            //Save.Enabled = false;
            Save.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Save_Click);

            SaveAs.Visible = true;
            //SaveAs.Enabled = false;
            SaveAs.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.SaveAs_Click);

            //CompareWithBase.Visible = true;
            //CompareWithBase.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.compareWithBase_Click);

            Search.Visible = true;
            Search.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Search_Click);

            Settings.Visible = true;
            Settings.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.Settings_Click);

            About.Visible = true;
            About.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(this.About_Click);

            object oName = applicationObject.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, applicationObject, null);
            oStandardBar = null;
            oCommandBars = null;

            clearRepository();
        }
Exemplo n.º 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;
             *
             */
        }
Exemplo n.º 16
0
 protected void InitApplication()
 {
     this.PptApplication = new PowerPointObj.Application();
     this.IsAppOpened    = true;
 }
Exemplo n.º 17
0
        internal static void Main(string[] args)
        {
            string arg = string.Join(" ", args);

            if (arg.Length < PREFIX.Length)
            {
                Forms.MessageBox.Show("Missing Argument. exitting...", TITLE, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation);
                return;
            }

            arg  = arg.Substring(PREFIX.Length); // trim a prefix
            args = arg.Split('#');
            string path = args[0];

#if !DEBUG
            // Dialog
            System.Reflection.Assembly asm;
            asm = System.Reflection.Assembly.GetExecutingAssembly();
            System.Resources.ResourceManager rm =
                new System.Resources.ResourceManager(
                    asm.GetName().Name + ".Properties.Resources", asm);

            string guardDialogMessage = rm.GetString("GuardDialog");
#endif

            try
            {
                if (path.EndsWith(".xlsx"))
                {
#if !DEBUG
                    Forms.DialogResult result = Forms.MessageBox.Show(
                        String.Format(guardDialogMessage, "Microsoft Excel", arg),
                        TITLE, Forms.MessageBoxButtons.YesNo,
                        Forms.MessageBoxIcon.Exclamation,
                        Forms.MessageBoxDefaultButton.Button2);
                    if (result == Forms.DialogResult.No)
                    {
                        return;
                    }
#endif
                    Excel._Application appl      = GetExcel();
                    Excel.Workbooks    workbooks = appl.Workbooks;
                    Excel.Workbook     workbook;
                    appl.Visible = true;
                    if (!path.Contains("%"))
                    {
                        workbook = workbooks.Open(path);
                    }
                    else
                    {
                        path     = Uri.UnescapeDataString(path);
                        workbook = workbooks.Open(path);
                    }

                    if (args.Length > 0) // if fragment exists
                    {
                        if (Exists(appl.Names, args[1]))
                        {
                            appl.Goto(args[1]);
                        }
                        else
                        {
                            SelectFragment(workbook, args[1]);
                        }
                    }
                    // bring up
                    workbook.Activate();
                    SetForegroundWindow(appl.Hwnd);
                }
                else if (path.EndsWith(".pptx"))
                {
#if !DEBUG
                    Forms.DialogResult result = Forms.MessageBox.Show(
                        String.Format(guardDialogMessage, "Microsoft PowerPoint", arg),
                        TITLE, Forms.MessageBoxButtons.YesNo,
                        Forms.MessageBoxIcon.Exclamation,
                        Forms.MessageBoxDefaultButton.Button2);
                    if (result == Forms.DialogResult.No)
                    {
                        return;
                    }
#endif
                    PowerPoint._Application  appl = GetPowerPoint();
                    PowerPoint.Presentations ppts = appl.Presentations;
                    PowerPoint.Presentation  ppt;
                    if (!path.Contains("%"))
                    {
                        ppt = ppts.Open(path);
                    }
                    else
                    {
                        path = Uri.UnescapeDataString(path);
                        ppt  = ppts.Open(path);
                    }

                    if (args.Length > 0) // if fragment exists
                    {
                        SelectFragment(ppt, args[1]);
                    }
                    // bring up
                    appl.Activate();
                    appl.Visible = MsoTriState.msoTrue;
                    SetForegroundWindow(appl.HWND);
                }
                else
                { // TODO: add another suffixes supporting
                    Forms.MessageBox.Show("only .xlsx is supported. exitting.", TITLE, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation);
                    return;
                }
            }
            catch (COMException ex)
            {
                Forms.MessageBox.Show(
                    (GetExcel().Name.Equals(ex.Source) ? ex.Message : "ファイルを開けませんでした。")
#if DEBUG
                    + "\r\n\r\n" + ex.StackTrace
#endif
                    , TITLE, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation);
            }
        }