예제 #1
0
        /// <summary>
        /// Open PPT App and opens dialog to select presentation
        /// </summary>
        /// <returns></returns>
        public bool OpenPowerPoint()
        {
            try
            {
                //Create an instance of PowerPoint.
                oPPT = new Application();
                // Show PowerPoint to the user.
                oPPT.Visible = MsoTriState.msoTrue;
                objPresSet   = oPPT.Presentations;
                OpenFileDialog Opendlg = new OpenFileDialog();

                Opendlg.Filter = "Powerpoint|*.ppt;*.pptx|All files|*.*";

                // Open file when user  click "Open" button
                if (Opendlg.ShowDialog() == true)
                {
                    string pptFilePath = Opendlg.FileName;
                    //open the presentation
                    objPres = objPresSet.Open(pptFilePath, MsoTriState.msoFalse,
                                              MsoTriState.msoTrue, MsoTriState.msoTrue);

                    objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
                    objPres.SlideShowSettings.Run();

                    oSlideShowView = objPres.SlideShowWindow.View;
                    return(true);
                }
                return(false);
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to open Power Point, please make sure you have the program installed correctly");
                return(false);
            }
        }
예제 #2
0
 public bool load(string file)
 {
     if (this.powerpoint == null)
     {
         return(false);
     }
     try
     {
         string fileName = file.Trim();
         presentations = powerpoint.Presentations;
         presentation  = presentations.Open(fileName,
                                            Microsoft.Office.Core.MsoTriState.msoFalse,
                                            Microsoft.Office.Core.MsoTriState.msoFalse,
                                            Microsoft.Office.Core.MsoTriState.msoTrue);
         slides = presentation.Slides;
         return(true);
     }
     catch
     {
         presentation = null;
         slides       = null;
         return(false);
     }
     //Thread.Sleep(5000);
 }
예제 #3
0
    public string  ReadSlide()
    {
        string presentationText = string.Empty;

        try
        {
            string filePath = System.Web.HttpContext.Current.Server.MapPath("~/TemplatePPT/Plantilla1.pptx");

            Application   pptApplication      = new Application();
            Presentations multi_presentations = pptApplication.Presentations;
            Presentation  presentation        = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            foreach (var item in presentation.Slides[1].Shapes)
            {
                var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                if (shape.HasTextFrame == MsoTriState.msoTrue)
                {
                    if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                    {
                        var textRange = shape.TextFrame.TextRange;
                        var text      = textRange.Text;

                        presentationText += text + " ";
                    }
                }
            }

            Console.WriteLine(presentationText);
        }
        catch (Exception ex)
        {
        }
        return(presentationText);
    }
        /// <summary>
        /// Open PPT App and opens dialog to select presentation
        /// </summary>
        /// <returns></returns>
        public bool OpenPowerPoint()
        {
            try
            {
                //Create an instance of PowerPoint.
                oPPT = new Application();
                // Show PowerPoint to the user.
                oPPT.Visible = MsoTriState.msoTrue;
                objPresSet = oPPT.Presentations;
                OpenFileDialog Opendlg = new OpenFileDialog();

                Opendlg.Filter = "Powerpoint|*.ppt;*.pptx|All files|*.*";

                // Open file when user  click "Open" button
                if (Opendlg.ShowDialog() == true)
                {
                    string pptFilePath = Opendlg.FileName;
                    //open the presentation
                    objPres = objPresSet.Open(pptFilePath, MsoTriState.msoFalse,
                    MsoTriState.msoTrue, MsoTriState.msoTrue);

                    objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
                    objPres.SlideShowSettings.Run();
                    
                    oSlideShowView = objPres.SlideShowWindow.View;
                    return true;
                }
                return false;
            }
            catch (Exception)
            {
                MessageBox.Show("Unable to open Power Point, please make sure you have the program installed correctly");
                return false;
            }
        }
예제 #5
0
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);

            base.OnCreate(bundle);

            // Create your application here
            SetContentView(Resource.Layout.PresentationView);

            (FindViewById <TextView> (Resource.Id.txtView)).Visibility = ViewStates.Gone;

            gestureDetector = new GestureDetector(this);
            _locMgr         = GetSystemService(Context.LocationService) as LocationManager;

            preses  = Presentations.GetPresentations();
            ivSlide = FindViewById <ImageView> (Resource.Id.ivSlide);

            selectedPresent = Intent.GetIntExtra("presentationID", 0);

            CreateTopLayout();
            RefreshParts();

            OnButtonTopClick(preses [selectedPresent].btn, null);

            OnButtonBottomClick(preses[selectedPresent].parts [Intent.GetIntExtra("partID", 0)].btn, null);
        }
예제 #6
0
        public static void SaveAsPPTFromImages(string imageFolder, string pptName)
        {
            var task = Task.Factory.StartNew(() =>
            {
                Application pptApp    = new Application();
                Presentations pptPres = pptApp.Presentations;
                Presentation pptPre   = pptPres.Add(MsoTriState.msoFalse);

                var imagesName = GetImageFilesPath(imageFolder);
                for (int i = 0; i < imagesName.Count; i++)
                {
                    // Slide start from 1
                    var slide     = pptPre.Slides.Add(i + 1, PpSlideLayout.ppLayoutObject);
                    var imageSize = ImageHelper.GetImageSize(imagesName[i]);
                    var slideSize = new Size((int)slide.Master.Width, (int)slide.Master.Height);
                    var scaleSize = FileUtils.GetScaleSize(imageSize, slideSize);
                    AddPictureShape(slide, imagesName[i], scaleSize);
                }

                // Save it as a ppt file
                pptPre.SaveAs(pptName, PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoCTrue);
            });

            task.Wait();
        }
예제 #7
0
        void PresenterInterface.StartPresintation()
        {
            Application ppApp = new Application();

            ppApp.Visible = MsoTriState.msoTrue;
            Presentations     ppPresens = ppApp.Presentations;
            Presentation      objPres   = ppPresens.Open(@"E:\\courseWork\\CourseProject\\CourseWork\\CourseWork\\exports\\presentation.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            Slides            objSlides = objPres.Slides;
            int               n         = objSlides.Count; //получаю количество слайдов в показываемой презентации
            SlideShowWindows  objSSWs;
            SlideShowSettings objSSS;


            objSSS             = objPres.SlideShowSettings;
            objSSS.EndingSlide = n - 2;
            objSSS.Run();
            objSSWs = ppApp.SlideShowWindows;

            Thread.Sleep(n * 5000);// пауза между слайдами так как 1 секунда переход 2 секунды слайд

            objPres.Close();
            ppApp.Quit();

            //закрываем потоки
            var processes = System.Diagnostics.Process.GetProcessesByName("POWERPNT");

            foreach (var p in processes)
            {
                p.Kill();
            }
        }
예제 #8
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            DocumentReader.Visibility = Visibility.Hidden;
            var window = new Presentations();

            transitioningControl.Content = window;
        }
예제 #9
0
        static void Main(string[] args)
        {
            if (!CheckInputFilePath(args[0]) || !CheckOutputFilePathDirectory(args[1]))
            {
                Console.WriteLine("Input Error : make sure you are providing correct input in console");
                Console.WriteLine("Help : your first argument is your input Presentation file. It must be a full file path like E:\\TestFile\\SlideQTestCount.pptx");
                Console.WriteLine("Help : your second argument is your output file. It must be a full file path and in this make sure the parent directory Exists on your system, file will be created automatically and only xls extention allowed like f:\\count.xls ");
                return;
            }
            Application ppApp = new Application();

            ppApp.Visible = MsoTriState.msoTrue;
            Presentations            oPresSet           = ppApp.Presentations;
            _Presentation            PPTObject          = oPresSet.Open(@args[0], MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
            SmellDetector            detector           = new SmellDetector();
            List <PresentationSmell> SlideDataModelList = detector.detectPresentationSmells(PPTObject.Slides);

            PPTObject.Close();
            try
            {
                Excelgenerator(SlideDataModelList, args[1]);
            }
            catch (Exception ex)
            {
                Console.WriteLine("message " + ex.Message);
            }
        }
예제 #10
0
        public static void ReadSlide()
        {
            try
            {
                string filePath = CurrentDirectory() + fileName;

                Application   pptApplication      = new Application();
                Presentations multi_presentations = pptApplication.Presentations;
                Presentation  presentation        = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                string presentationText = string.Empty;
                foreach (var item in presentation.Slides[1].Shapes)
                {
                    var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                    if (shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            var textRange = shape.TextFrame.TextRange;
                            var text      = textRange.Text;

                            presentationText += text + " ";
                        }
                    }
                }

                Console.WriteLine(presentationText);
            }
            catch (Exception ex)
            {
                WriteException(ex.ToString());
            }
        }
예제 #11
0
        static public void StartApp()
        {
            app  = new Application();
            ppts = app.Presentations;

            app.SlideShowNextSlide += OnNextSlide;
            app.SlideShowEnd       += OnSlideShowEnd;
        }
예제 #12
0
 public void LoadFile(string fileName)
 {
     _presentations = _app.Presentations;
     _presentation = _presentations.Open(fileName,
                                         MsoTriState.msoFalse,
                                         MsoTriState.msoFalse,
                                         MsoTriState.msoTrue);
 }
        private void ViewPresentation()
        {
            Presentations presentations = Globals.ThisAddIn.Application.Presentations;

            #region initialize powerpoint template
            //now open the template format for the presentation
            if (_directoryPath.Length == 0)
            {
                if (!File.Exists(Config.PPTTemplate))
                {
                    throw new ApplicationException("Template not found.");
                }

                //Globals.ThisAddIn.Application.ActivePresentation.Close();

                //ByteToFile(Properties.Resources.packageTemplate, Config.PPTTemplate);

                //presentation = presentations.Open(
                //    Config.PPTTemplate,
                //    MsoTriState.msoCTrue,
                //    MsoTriState.msoCTrue,
                //    MsoTriState.msoCTrue);
            }
            else
            {
                presentation = Globals.ThisAddIn.Application.ActivePresentation;
            }
            //get the template slides
            slides = presentation.Slides;
            if (slides.Count < 5)
            {
                throw new ApplicationException("Template was altered.");
            }
            #endregion


            /* Create package poster */
            CreatePackageSlide();
            CreateEventSlide();
            CreateChartSlide();
            //delete the four template slide
            for (int i = 1; i <= 4; i++)
            {
                slides[1].Delete();
            }

            if (_directoryPath.Length > 0)
            {
                _pptxFileName += DateTime.Now.ToString("MMddyyyyhhmmss");
                presentation.SaveAs(
                    Path.Combine(_directoryPath, _pptxFileName),
                    PpSaveAsFileType.ppSaveAsDefault,
                    MsoTriState.msoTrue);
                File.SetAttributes(_fullName, FileAttributes.Archive);
                File.Delete(_fullName);
            }
        }
예제 #14
0
        public PresentationModule(IUnityContainer container, Presentations presentations)
            : base(container)
        {
            if (presentations == null)
            {
                throw new ArgumentNullException(nameof(presentations));
            }

            _presentations = presentations;
        }
예제 #15
0
        SlideNotes[] Extract(string filename)
        {
            List <SlideNotes> slideNotes    = new List <SlideNotes>();
            Application       app           = new Application();
            Presentations     presentations = app.Presentations;
            Presentation      presentation  = presentations.Open(filename);

            foreach (Slide slide in presentation.Slides)
            {
                if (slide.HasNotesPage != MsoTriState.msoTrue)
                {
                    continue;
                }

                List <string> list       = new List <string>();
                SlideRange    notesPages = slide.NotesPage;
                foreach (Microsoft.Office.Interop.PowerPoint.Shape shape in notesPages.Shapes)
                {
                    if (shape.Type == MsoShapeType.msoPlaceholder)
                    {
                        if (shape.PlaceholderFormat.Type == PpPlaceholderType.ppPlaceholderBody)
                        {
                            if (shape.HasTextFrame == MsoTriState.msoTrue)
                            {
                                if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                                {
                                    var      textRange = shape.TextFrame.TextRange;
                                    string[] lines     = textRange.Text.Split(new[] { "\r\n", "\r", "\n" },
                                                                              StringSplitOptions.None
                                                                              );
                                    foreach (string line in lines)
                                    {
                                        if (line.Length > 0)
                                        {
                                            list.Add(line);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                SlideNotes current = new SlideNotes
                {
                    Name        = slide.Name,
                    Notes       = list.ToArray(),
                    SlideNumber = slide.SlideNumber,
                    Total       = presentation.Slides.Count
                };
                slideNotes.Add(current);
            }
            app.Quit();

            return(slideNotes.ToArray());
        }
예제 #16
0
 public void ChangePresentation(string presentationName)
 {
     if (Presentations != null)
     {
         var presentation = Presentations.FirstOrDefault(i => string.Equals(i.Name, presentationName));
         if (presentation != null)
         {
             ChangePresentation(presentation);
         }
     }
 }
        public ResponseModel ConvertPptToPdf(string fileLocation, string outLocation)
        {
            Microsoft.Office.Interop.PowerPoint.Application app = null;
            Presentations presentations = null;
            Presentation  presentation  = null;

            try
            {
                if (!File.Exists(outLocation))
                {
                    app = new Microsoft.Office.Interop.PowerPoint.Application
                    {
                        Visible = MsoTriState.msoTrue
                    };
                    presentations = app.Presentations;
                    presentation  = presentations.Open(fileLocation, ReadOnly: MsoTriState.msoCTrue);
                    presentation.ExportAsFixedFormat(outLocation, PpFixedFormatType.ppFixedFormatTypePDF);

                    Marshal.ReleaseComObject(presentations);
                    presentation.Close();
                    Marshal.ReleaseComObject(presentation);
                    app.Quit();
                    Marshal.ReleaseComObject(app);
                }
                else
                {
                    return(new ResponseModel {
                        IsSucceed = false, ErrorMessage = outLocation + " file-ı artıq mövcuddur."
                    });
                }

                if (!File.Exists(outLocation))
                {
                    return(new ResponseModel {
                        IsSucceed = false, ErrorMessage = outLocation + " file-ı tapılmadı."
                    });
                }

                return(new ResponseModel {
                    Data = outLocation, IsSucceed = true, ErrorMessage = string.Empty
                });
            }
            catch (Exception e)
            {
                Marshal.ReleaseComObject(presentations);
                presentation.Close();
                Marshal.ReleaseComObject(presentation);
                app.Quit();
                Marshal.ReleaseComObject(app);
                return(new ResponseModel {
                    IsSucceed = false, ErrorMessage = "File convert oluna bilmədi: " + e.Message
                });
            }
        }
예제 #18
0
 private PowerPoint(string fileName)
 {
     string appProgID = "PowerPoint.Application";
     Type pptType = Type.GetTypeFromProgID(appProgID);
     _application = (Application)Activator.CreateInstance(pptType, true);
     //_application.Visible = MsoTriState.msoTrue;
     _presentations = _application.Presentations;
     _presentation = _presentations.Open(fileName,
                                         MsoTriState.msoTrue,
                                         MsoTriState.msoTrue,
                                         MsoTriState.msoFalse);
 }
예제 #19
0
        public void GetPPTObject()
        {
            string      solution_dir = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.WorkDirectory));
            string      path         = @solution_dir + @"\TestFile\DECAF.pptx";
            string      absolute     = Path.GetFullPath(path);
            Application ppApp        = new Application();

            ppApp.Visible = MsoTriState.msoTrue;
            Presentations oPresSet = ppApp.Presentations;

            pptObject = oPresSet.Open(@path, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
        }
예제 #20
0
        public static void createPresentation(List <KeyValuePair <string, float> > titles)
        {
            Microsoft.Office.Interop.PowerPoint.Application oPowerPoint = new Microsoft.Office.Interop.PowerPoint.Application();
            oPowerPoint.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            System.Console.WriteLine("PowerPoint application created.");
            Presentations oPres   = oPowerPoint.Presentations;
            Presentation  oPre    = oPres.Add(MsoTriState.msoTrue);
            Slides        oSlides = oPre.Slides;

            int nr = 1;

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

            //Clean up the unmanaged COM resource.
            if (oSlides != null)
            {
                Marshal.FinalReleaseComObject(oSlides);
                oSlides = null;
            }
            if (oPre != null)
            {
                Marshal.FinalReleaseComObject(oPre);
                oPre = null;
            }
            if (oPres != null)
            {
                Marshal.FinalReleaseComObject(oPres);
                oPres = null;
            }
            if (oPowerPoint != null)
            {
                Marshal.FinalReleaseComObject(oPowerPoint);
                oPowerPoint = null;
            }
        }
예제 #21
0
        public void GetPPTObject()
        {
            string      solution_dir = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.WorkDirectory));
            string      path         = @solution_dir + @"\TestFile\Table.pptx";
            string      absolute     = Path.GetFullPath(path);
            Application ppApp        = new Application();

            ppApp.Visible = MsoTriState.msoTrue;
            Presentations oPresSet = ppApp.Presentations;

            PPTObject = oPresSet.Open(@path, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoTrue);
            SmellDetector detector = new SmellDetector();

            SlideDataModelList = detector.detectPresentationSmells(PPTObject.Slides);
        }
예제 #22
0
        public bool startSlideShow()
        {
            if (this.powerpoint == null)
            {
                return(false);
            }
            if (this.powerpoint.Presentations.Count == 0)
            {
                return(false);
            }

            stopSlideShow();
            if (slides == null)
            {
                presentations = powerpoint.Presentations;
                presentation  = presentations._Index(1);
                if (presentation != null)
                {
                    slides = presentation.Slides;
                }
            }
            if (slides != null)
            {
                int   all      = slides.Count;
                int[] SlideIdx = new int[all];
                for (int i = 0; i < all; i++)
                {
                    SlideIdx[i] = i + 1;
                }
                slideRange = slides.Range(SlideIdx);

                slideShowTransition = slideRange.SlideShowTransition;
                slideShowTransition.AdvanceOnTime = Microsoft.Office.Core.MsoTriState.msoFalse;
                slideShowTransition.EntryEffect   = Microsoft.Office.Interop.PowerPoint.PpEntryEffect.ppEffectBoxOut;

                //Prevent Office Assistant from displaying alert messages:
                //dumps if NotFiniteNumberException installed   bAssistantOn = powerpoint.Assistant.On;
                //   powerpoint.Assistant.On = false;
                //Run the Slide show
                slideShowSettings = presentation.SlideShowSettings;
                slideShowSettings.StartingSlide = 1;
                slideShowSettings.EndingSlide   = all;
                slideShowWindow  = slideShowSettings.Run();
                slideShowWindows = powerpoint.SlideShowWindows;
            }

            return(true);
        }
        protected override void OnCreate(Bundle bundle)
        {
            RequestWindowFeature(WindowFeatures.NoTitle);

            base.OnCreate(bundle);

            // Create your application here
            SetContentView(Resource.Layout.PresentationView);

            Window.AddFlags(WindowManagerFlags.KeepScreenOn);

            (FindViewById <TextView> (Resource.Id.txtView)).Visibility = ViewStates.Gone;

            gestureDetector = new GestureDetector(this);
            _locMgr         = GetSystemService(Context.LocationService) as LocationManager;

            preses   = Presentations.GetPresentations();
            ivSlide  = FindViewById <ImageView> (Resource.Id.ivSlide);
            doctorID = Intent.GetIntExtra("doctorID", 0);
            if (doctorID == 0)
            {
                Finish();
            }

            doctor = DoctorManager.GetDoctor(doctorID, false);
            if (doctor == null)
            {
                Finish();
            }

            lastSlideTime         = DateTime.Now;
            demonstration         = DemonstrationManager.GetDemonstration(doctorID, DateTime.Today);
            demonstration.analyze = doctor.LastVisitAnalyze;

            if (demonstration.visitTime.Date != DateTime.Today)
            {
                demonstration.visitTime = DateTime.Now;
            }

            selectedPresent = Intent.GetIntExtra("presentationID", 0);

            CreateTopLayout();
            RefreshParts();

            OnButtonTopClick(preses [selectedPresent].btn, null);

            OnButtonBottomClick(preses[selectedPresent].parts [Intent.GetIntExtra("partID", 0)].btn, null);
        }
예제 #24
0
        static public void OpenPPTXPresentation(string pptxPath)
        {
            PowerPoint.Application pptxApplicatoin = new PowerPoint.Application();
            pptxApplicatoin.Visible = MsoTriState.msoTrue;
            Presentations pptxPresentations = pptxApplicatoin.Presentations;
            Presentation  presentation      = pptxPresentations.Open(pptxPath,
                                                                     MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
            Slides            objSlides = presentation.Slides;
            SlideShowWindows  SSWindows;
            SlideShowSettings objSSS;

            objSSS = presentation.SlideShowSettings;
            objSSS.Run();
            SSWindows = pptxApplicatoin.SlideShowWindows;
            pptxApplicatoin.Quit();
        }
예제 #25
0
 static public bool CheckApp()
 {
     try
     {
         app  = new Application();
         ppts = app.Presentations;
     }
     catch
     {
         app  = null;
         ppts = null;
         return(false);
     }
     app  = null;
     ppts = null;
     return(true);
 }
예제 #26
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Create your application here
            preses = Presentations.GetPresentations();

            items = new List <Tuple <string> >();
            for (int i = 0; i <= preses.Count - 1; i++)
            {
                for (int j = 0; j <= preses[i].parts.Count - 1; j++)
                {
                    items.Add(new Tuple <string>(preses[i].name + "." + preses[i].parts[j].name));
                }
            }

            this.ListAdapter = new ArrayAdapter <Tuple <string> > (this, Android.Resource.Layout.SimpleListItem1, items);
        }
예제 #27
0
        private static bool WriteOnSlide()
        {
            var    resultado = false;
            string filePath  = CurrentDirectory() + fileName;

            try
            {
                Application   pptApplication      = new Application();
                Presentations multi_presentations = pptApplication.Presentations;
                Presentation  presentation        = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
                CustomLayout  customLayout        = presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

                Slides slides = presentation.Slides;
                Microsoft.Office.Interop.PowerPoint.Shapes shapes = presentation.Slides[1].Shapes;
                TextRange objText;

                slides = presentation.Slides;

                var text1 = "Esto es una prueba de escribir en el titulo";
                var text2 = "Estoy escribiendo en la seccion de contenido de la diapositiva PPT";

                objText           = shapes[1].TextFrame.TextRange;
                objText.Text      = text1;
                objText.Font.Name = "Arial";
                objText.Font.Size = 32;

                objText           = shapes[2].TextFrame.TextRange;
                objText.Text      = text2;
                objText.Font.Name = "Arial";
                objText.Font.Size = 28;

                ReadWriteTxt(filePath);
                presentation.SaveAs(filePath, PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
                presentation.Close();
                pptApplication.Quit();

                resultado = true;
            }
            catch (Exception ex)
            {
                WriteException(ex.ToString());
            }
            return(resultado);
        }
예제 #28
0
        public static bool ConvertPowerPointToPdf(string inputFile, string outputfile)
        {
            string outputFileName = outputfile;

            Microsoft.Office.Interop.PowerPoint.Application powerPointApp =
                new Microsoft.Office.Interop.PowerPoint.Application();
            Presentation  presentation  = null;
            Presentations presentations = null;

            try
            {
                presentations = powerPointApp.Presentations;
                presentation  = presentations.Open(inputFile, MsoTriState.msoFalse, MsoTriState.msoFalse,
                                                   MsoTriState.msoFalse);

                presentation.ExportAsFixedFormat(outputFileName, PpFixedFormatType.ppFixedFormatTypePDF,
                                                 PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse,
                                                 PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PpPrintOutputType.ppPrintOutputSlides,
                                                 MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, string.Empty, false, true, true, true, false,
                                                 Type.Missing);
            }
            catch (Exception)
            {
                MessageBox.Show("Co loi xay ra");
                return(false);
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    Marshal.ReleaseComObject(presentation);
                    presentation = null;
                }
                if (powerPointApp != null)
                {
                    powerPointApp.Quit();
                    Marshal.ReleaseComObject(powerPointApp);
                    powerPointApp = null;
                }
            }
            return(true);
        }
예제 #29
0
    public bool WriteOnSlide()
    {
        var    resultado = false;
        string filePath  = System.Web.HttpContext.Current.Server.MapPath("~/TemplatePPT/Plantilla1.pptx");

        try
        {
            Application   pptApplication      = new Application();
            Presentations multi_presentations = pptApplication.Presentations;
            Presentation  presentation        = multi_presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
            CustomLayout  customLayout        = presentation.SlideMaster.CustomLayouts[PpSlideLayout.ppLayoutText];

            Slides slides = presentation.Slides;
            Microsoft.Office.Interop.PowerPoint.Shapes shapes = presentation.Slides[1].Shapes;
            TextRange objText;

            slides = presentation.Slides;

            var text1 = "Escribiendo en el titulo: " + DateTime.Now.ToString();
            var text2 = "Descripcion PPT: " + DateTime.Now.ToString();

            objText           = shapes[1].TextFrame.TextRange;
            objText.Text      = text1;
            objText.Font.Name = "Arial";
            objText.Font.Size = 32;

            objText           = shapes[2].TextFrame.TextRange;
            objText.Text      = text2;
            objText.Font.Name = "Arial";
            objText.Font.Size = 28;

            ReadWriteTxt(filePath);
            presentation.SaveAs(filePath, PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);
            presentation.Close();
            pptApplication.Quit();
            resultado = true;
        }
        catch (Exception ex)
        {
        }
        return(resultado);
    }
예제 #30
0
 public bool load(string file)
 {
     if (this.powerpoint == null) return false;
       try
       {
     string fileName = file.Trim();
     presentations = powerpoint.Presentations;
     presentation = presentations.Open(fileName,
                                   Microsoft.Office.Core.MsoTriState.msoFalse,
                                   Microsoft.Office.Core.MsoTriState.msoFalse,
                                   Microsoft.Office.Core.MsoTriState.msoTrue);
     slides = presentation.Slides;
     return true;
       }
       catch
       {
     presentation = null;
     slides = null;
     return false;
       }
       //Thread.Sleep(5000);
 }
예제 #31
0
        public void Dispose()
        {
            if (_disposed) return;

            if (_slide != null)
            {
                Marshal.ReleaseComObject(_slide);
                _slide = null;
            }

            if (_slides != null)
            {
                Marshal.ReleaseComObject(_slides);
                _slide = null;
            }

            if (_presentation != null)
            {
                _presentation.Close();
                Marshal.ReleaseComObject(_presentation);
                _presentation = null;
            }

            if (_presentations != null)
            {
                Marshal.ReleaseComObject(_presentations);
                _presentations = null;
            }

            if (_application != null)
            {
                _application.Quit();
                Marshal.ReleaseComObject(_application);
                _application = null;
            }
            _disposed = true;

            GC.SuppressFinalize(this);
        }
예제 #32
0
        private static void ConvertPowerPointToPdf(string filePath)
        {
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath);
            string outputFilePath           = OutputFolder + fileNameWithoutExtension + ".pdf";

            Microsoft.Office.Interop.PowerPoint.ApplicationClass applicationClass = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            Presentation presentation = null;

            try
            {
                Presentations presentations = applicationClass.Presentations;
                presentation = presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
                presentation.ExportAsFixedFormat(outputFilePath, PpFixedFormatType.ppFixedFormatTypePDF,
                                                 PpFixedFormatIntent.ppFixedFormatIntentScreen, MsoTriState.msoFalse,
                                                 PpPrintHandoutOrder.ppPrintHandoutVerticalFirst, PpPrintOutputType.ppPrintOutputSlides,
                                                 MsoTriState.msoFalse, null, PpPrintRangeType.ppPrintAll, string.Empty, false, true, true, true, false, Type.Missing);
            }
            catch (System.Exception e)
            {
                log.Error("Eccezione durante la conversione del file PowerPoint " + filePath);
                log.Error(e.StackTrace);
                File.Move(filePath, ErrorFolder + Path.GetFileName(filePath));
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    Marshal.ReleaseComObject(presentation);
                }
                if (applicationClass != null)
                {
                    applicationClass.Quit();
                    Marshal.ReleaseComObject(applicationClass);
                }
                CloseProcess("powerpnt");
                File.Delete(filePath);
            }
        }
예제 #33
0
        public bool startSlideShow()
        {
            if (this.powerpoint == null) return false;
              if (this.powerpoint.Presentations.Count == 0) return false;

              stopSlideShow();
              if (slides == null)
              {
              presentations = powerpoint.Presentations;
              presentation = presentations._Index(1);
              if (presentation != null)
              {
              slides = presentation.Slides;
              }
              }
              if (slides != null)
              {

              int all = slides.Count;
              int[] SlideIdx = new int[all];
              for (int i = 0; i < all; i++) SlideIdx[i] = i + 1;
              slideRange = slides.Range(SlideIdx);

              slideShowTransition = slideRange.SlideShowTransition;
              slideShowTransition.AdvanceOnTime = Microsoft.Office.Core.MsoTriState.msoFalse;
              slideShowTransition.EntryEffect = Microsoft.Office.Interop.PowerPoint.PpEntryEffect.ppEffectBoxOut;

              //Prevent Office Assistant from displaying alert messages:
              //dumps if NotFiniteNumberException installed   bAssistantOn = powerpoint.Assistant.On;
              //   powerpoint.Assistant.On = false;
              //Run the Slide show
              slideShowSettings = presentation.SlideShowSettings;
              slideShowSettings.StartingSlide = 1;
              slideShowSettings.EndingSlide = all;
              slideShowWindow = slideShowSettings.Run();
              slideShowWindows = powerpoint.SlideShowWindows;
              }

              return true;
        }
        /// <inheritdoc />
        public override void Initialize()
        {
            try
            {
                var textTabPresentation = new TextTabPresentation(Core);
                textTabPresentation.SetView(new TextTabView());
                RegisterPresentation(textTabPresentation);

                var buttonsTabPresentation = new ButtonsTabPresentation(Core);
                buttonsTabPresentation.SetView(new ButtonsTabView());
                RegisterPresentation(buttonsTabPresentation);

                var comboBoxesTabPresentation = new ComboBoxesTabPresentation(Core);
                comboBoxesTabPresentation.SetView(new ComboBoxesTabView());
                RegisterPresentation(comboBoxesTabPresentation);

                var checkBoxesTabPresentation = new CheckBoxesTabPresentation(Core);
                checkBoxesTabPresentation.SetView(new CheckBoxesTabView());
                RegisterPresentation(checkBoxesTabPresentation);

                var radioButtonsTabPresentation = new RadioButtonsTabPresentation(Core);
                radioButtonsTabPresentation.SetView(new RadioButtonsTabView());
                RegisterPresentation(radioButtonsTabPresentation);

                var textBoxesTabPresentation = new TextBoxesTabPresentation(Core);
                textBoxesTabPresentation.SetView(new TextBoxesTabView());
                RegisterPresentation(textBoxesTabPresentation);

                var listBoxesTabPresentation = new ListBoxesTabPresentation(Core);
                listBoxesTabPresentation.SetView(new ListBoxesTabView());
                RegisterPresentation(listBoxesTabPresentation);

                var progressBarsTabPresentation = new ProgressBarsTabPresentation(Core);
                progressBarsTabPresentation.SetView(new ProgressBarsTabView());
                RegisterPresentation(progressBarsTabPresentation);

                var menusTabPresentation = new MenusTabPresentation(Core);
                menusTabPresentation.SetView(new MenusTabView());
                RegisterPresentation(menusTabPresentation);

                var chartingTabPresentation = new ChartingTabPresentation(Core);
                chartingTabPresentation.SetView(new ChartingTabView());
                RegisterPresentation(chartingTabPresentation);

                //var configurationTabPresentation = new ConfigurationTabPresentation(Core);
                //configurationTabPresentation.SetView(new ConfigurationTabView());
                //RegisterPresentation(configurationTabPresentation);

                var coreTabPresentation = new CoreTabPresentation(Core);
                coreTabPresentation.SetView(new CoreTabView());
                RegisterPresentation(coreTabPresentation);

                var themeTabPresentation = new ThemeTabPresentation(Core);
                themeTabPresentation.SetView(new ThemeTabView());
                RegisterPresentation(themeTabPresentation);

                var aboutTabPresentation = new AboutTabPresentation(Core);
                aboutTabPresentation.SetView(new AboutTabView());
                RegisterPresentation(aboutTabPresentation);

                OnMessageReceived(new Message("Initialization", "Main tab controller initialized.", "Main tab controller", MessageType.Success));

                if (Presentations.Count > 0)
                {
                    SelectedPresentation = Presentations.First();
                }
            }
            catch (Exception e)
            {
                OnMessageReceived(new Message("Initialization", "Error initialization main tab controller:\r\n" + e, "Main tab controller", MessageType.Error));
            }
        }
예제 #35
0
        /// <summary>
        /// Prints a document using interop services.
        /// </summary>
        /// <param name="file">The file to print.</param>
        /// <param name="printQueue">The <see cref="PrintQueue" /> to print the file to.</param>
        /// <param name="printOptions">The <see cref="FilePrintOptions" /> to use for printing the file.</param>
        /// <returns>A <see cref="FilePrintResult" /> object representing the outcome of the print operation.</returns>
        protected override FilePrintResult PrintInterop(FileInfo file, PrintQueue printQueue, FilePrintOptions printOptions)
        {
            ProcessUtil.KillProcess("POWERPNT");

            Application   powerpoint    = null;
            Presentations presentations = null;
            Presentation  presentation  = null;

            try
            {
                OnStatusChanged("Starting PowerPoint");
                powerpoint = new Application();
                powerpoint.DisplayAlerts = PpAlertLevel.ppAlertsNone;

                OnStatusChanged("Opening file: " + file.Name);
                presentations = powerpoint.Presentations;
                presentation  = presentations.Open(file.FullName,
                                                   ReadOnly: MsoTriState.msoCTrue,
                                                   WithWindow: MsoTriState.msoFalse);

                // Check for the word "on" in the queue name.  If it exists, include the port in the name.
                string queueName = printQueue.FullName;
                if (queueName.Contains(" on ") || queueName.StartsWith("on ", false, CultureInfo.CurrentCulture) || queueName.EndsWith(" on", false, CultureInfo.CurrentCulture))
                {
                    queueName = GetQueueNameWithPort(printQueue);
                }

                try
                {
                    OnStatusChanged($"Setting active printer to {queueName}");
                    presentation.PrintOptions.ActivePrinter = queueName;
                }
                catch
                {
                    throw new FilePrintException($"PowerPoint cannot print to '{queueName}'.  Check the formatting of the queue name.");
                }

                OnStatusChanged("Printing to: " + queueName);
                DateTimeOffset startTime = DateTimeOffset.Now;
                presentation.PrintOptions.PrintInBackground = MsoTriState.msoFalse;
                presentation.PrintOut(Copies: printOptions.Copies, Collate: MsoTriState.msoFalse);
                DateTimeOffset endtime = DateTimeOffset.Now;

                OnStatusChanged("Closing presentation...");
                presentation.Close();

                OnStatusChanged("Quitting PowerPoint.");
                powerpoint.Quit();

                return(new FilePrintResult(startTime, endtime));
            }
            finally
            {
                if (presentation != null)
                {
                    Marshal.FinalReleaseComObject(presentation);
                    presentation = null;
                }

                if (presentations != null)
                {
                    Marshal.FinalReleaseComObject(presentations);
                    presentations = null;
                }

                if (powerpoint != null)
                {
                    Marshal.FinalReleaseComObject(powerpoint);
                    powerpoint = null;
                }

                GarbageCollect();
            }
        }
예제 #36
0
 public PowerPointOperationContext()
 {
     Application   = new Application();
     Presentations = Application.Presentations;
     _tempFilePath = new List <string>();
 }
예제 #37
0
        public void CloseApplication()
        {

            if (_presentation != null)
            {
                _presentation.Close();
                Marshal.ReleaseComObject(_presentation);
                _presentation = null;
            }

            if (_presentations != null)
            {
                Marshal.ReleaseComObject(_presentations);
                _presentations = null;
            }
            if (_app != null)
            {
                _handler = IntPtr.Zero;

                object saveChanges = false;
                _app.Quit();
                _app = null;
            }
        }