public void GetPPTObject()
        {
            string      solution_dir = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.WorkDirectory));
            string      path         = @solution_dir + @"\TestFile\SecretaryofHiPU.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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
 }
Esempio n. 4
0
        /// <summary>
        /// Создать файл презентации
        /// </summary>
        /// <param name="ppFilePath">Полный путь к файлу с презентацией</param>
        /// <param name="pptFiledbId">id презентации в БД</param>
        /// <param name="archivePath">Полный путь к архиву, содержащему презентацию ()</param>
        public PPTFile(string ppFilePath, long pptFiledbId, string archivePath = null)
        {
            Microsoft.Office.Interop.PowerPoint._Application  powerPointApp   = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations ppPresentations = powerPointApp.Presentations;
            _Presentation = ppPresentations.Open(ppFilePath, MsoTriState.msoCTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

            if (archivePath == null)
            {
                _PresentationInfo = new PresentationInfo(ppFilePath)
                {
                    SlidersInfo = new List <SlideInfo>(), DbId = pptFiledbId
                }
            }
            ;
            else
            {
                _PresentationInfo = new PresentationInfo(archivePath)
                {
                    SlidersInfo = new List <SlideInfo>(), DbId = pptFiledbId
                }
            };
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        public void quitPresentation(Presentation presentation)
        {
            //Reenable Office Assisant, if it was on:
              if (this.powerpoint == null) return;
              if (this.powerpoint.Presentations.Count == 0) return;
              if (presentation == null) return;

              //if (this.bAssistantOn)
              //{
              //  this.powerpoint.Assistant.On = true;
              //  this.powerpoint.Assistant.Visible = false;
              //}
              presentation.Close();
              if (presentation == this.presentation) this.presentation = null;
        }
Esempio n. 7
0
        public static bool ConvertToNewOfficeDocument(string fileName, out string newFileName, out string newExt)
        {
            var ext = Path.GetExtension(fileName).ToLower();

            newExt = ext;

            newFileName = fileName;

            if (!DestinationDictionary.ContainsKey(ext))
            {
                return(false);
            }
            if (fileName.StartsWith("~*"))
            {
                return(false);
            }

            var dest = DestinationDictionary[ext];

            newExt = dest.Extension;

            newFileName = ReplaceExtension(fileName, dest.Extension);

            object obj;

            var result = true;

            switch (dest.Application)
            {
            case OfficeApplication.Word:
                if (_wordApp == null)
                {
                    _wordApp = new Application();
                }
                _Document wordDoc = null;

                try
                {
                    wordDoc = _wordApp.Documents.Open(fileName);
                    wordDoc.Convert();
                    if (wordDoc.HasVBProject)
                    {
                        newFileName = ReplaceExtension(newFileName, ".docm");
                        dest        = new OfficeDestination(OfficeApplication.Word, ".docm",
                                                            WdSaveFormat.wdFormatXMLDocumentMacroEnabled); //for files with macro
                    }
                    wordDoc.SaveAs(newFileName, dest.FileFormat);
                }
                catch (Exception e)
                {
                    newFileName = fileName;
                    result      = false;
                    DisplayError(fileName, e);
                }
                finally
                {
                    if (wordDoc != null)
                    {
                        wordDoc.Close();
                        obj = wordDoc;
                        DisposeInteropObject(ref obj);
                    }
                    if (!KeepOpen || !result)
                    {
                        _wordApp.Quit();
                        obj = _wordApp;
                        DisposeInteropObject(ref obj);
                        _wordApp = null;
                    }
                }
                break;

            case OfficeApplication.Excel:
                if (_excelApp == null)
                {
                    _excelApp = new Microsoft.Office.Interop.Excel.Application();
                }
                _Workbook excelDoc = null;
                try
                {
                    excelDoc = _excelApp.Workbooks.Open(fileName);
                    if (excelDoc.HasVBProject)
                    {
                        newFileName = ReplaceExtension(newFileName, ".xlsm");
                        dest        = new OfficeDestination(OfficeApplication.Excel, ".xlsm",
                                                            XlFileFormat.xlOpenXMLWorkbookMacroEnabled); //for files with macro
                    }
                    excelDoc.SaveAs(newFileName, dest.FileFormat);
                }
                catch (Exception e)
                {
                    newFileName = fileName;
                    result      = false;
                    DisplayError(fileName, e);
                }
                finally
                {
                    if (excelDoc != null)
                    {
                        excelDoc.Close();
                        obj = excelDoc;
                        DisposeInteropObject(ref obj);
                    }
                    if (!KeepOpen || !result)
                    {
                        _excelApp.Quit();
                        obj = _excelApp;
                        DisposeInteropObject(ref obj);
                        _excelApp = null;
                    }
                }
                break;

            case OfficeApplication.PowerPoint:
                if (_powerpointApp == null)
                {
                    _powerpointApp = new Microsoft.Office.Interop.PowerPoint.Application();
                }
                _Presentation powerpointDoc = null;
                try
                {
                    powerpointDoc = _powerpointApp.Presentations.Open(fileName, MsoTriState.msoTrue,
                                                                      MsoTriState.msoTrue, MsoTriState.msoFalse);
                    if (powerpointDoc.HasVBProject)
                    {
                        newFileName = ReplaceExtension(newFileName, ".pptm");
                        dest        = new OfficeDestination(OfficeApplication.PowerPoint, ".pptm",
                                                            PpSaveAsFileType.ppSaveAsOpenXMLPresentationMacroEnabled); //for files with macro
                    }
                    powerpointDoc.SaveAs(newFileName, (PpSaveAsFileType)dest.FileFormat);
                }
                catch (Exception e)
                {
                    newFileName = fileName;
                    result      = false;
                    DisplayError(fileName, e);
                }
                finally
                {
                    if (powerpointDoc != null)
                    {
                        powerpointDoc.Close();
                        obj = powerpointDoc;
                        DisposeInteropObject(ref obj);
                    }
                    if (!KeepOpen || !result)
                    {
                        _powerpointApp.Quit();
                        obj = _powerpointApp;
                        DisposeInteropObject(ref obj);
                        _powerpointApp = null;
                    }
                }
                break;
            }

            GarbageCollector();
            return(result);
        }
    /// <summary>
    /// Создать файл презентации
    /// </summary>
    /// <param name="ppFilePath">Полный путь к файлу с презентацией</param>
    /// <param name="pptFiledbId">id презентации в БД</param>
    /// <param name="archivePath">Полный путь к архиву, содержащему презентацию ()</param>
    public PPTFile(string ppFilePath, long pptFiledbId, string archivePath = null)
    {
      Microsoft.Office.Interop.PowerPoint._Application powerPointApp = new Microsoft.Office.Interop.PowerPoint.Application();
      Microsoft.Office.Interop.PowerPoint.Presentations ppPresentations = powerPointApp.Presentations;
      _Presentation = ppPresentations.Open(ppFilePath, MsoTriState.msoCTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

      if (archivePath == null)
        _PresentationInfo = new PresentationInfo(ppFilePath) { SlidersInfo = new List<SlideInfo>(), DbId = pptFiledbId };
      else
        _PresentationInfo = new PresentationInfo(archivePath) { SlidersInfo = new List<SlideInfo>(), DbId = pptFiledbId };
    }
 public MppPresentatie(Presentation presentatie)
 {
     _presentatie = presentatie;
     slideTeller  = 0;
 }