Exemple #1
1
 private void MonthClosed()
 {
     Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
     Microsoft.Office.Core.MsoTriState ofalse = Microsoft.Office.Core.MsoTriState.msoFalse;
     Microsoft.Office.Core.MsoTriState otrue  = Microsoft.Office.Core.MsoTriState.msoTrue;
     pptApp.Visible = otrue;
     pptApp.Activate();
     Microsoft.Office.Interop.PowerPoint.Presentations ps = pptApp.Presentations;
     Microsoft.Office.Interop.PowerPoint.Presentation  p  = ps.Open(@"F:\Mess Managment\Mess Notice\PPTFormatNotice\MonthClosed.pptx", ofalse, ofalse, otrue);
     System.Diagnostics.Debug.Print(p.Windows.Count.ToString());
 }
 public CreateQuestionView()
 {
     InitializeComponent();
     grdQuestions.AutoGenerateColumns = false;
     _app = Globals.ThisAddIn.Application;
     InitQuestionSlide();
 }
Exemple #3
0
        /// <summary>
        /// PPT转成Html
        /// </summary>
        /// <param name="physicalPath">文件物理路径 绝对路径</param>
        /// <param name="serverPath">文件服务器路径 相对路径</param>
        /// <returns></returns>
        public static OfficeResult PPTToHtml(string physicalPath, string serverPath)
        {
            OfficeResult res = new OfficeResult();

            try
            {
                //-------------------------------------------------
                Microsoft.Office.Interop.PowerPoint.Application  ppApp   = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(physicalPath, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
                string htmlName   = Path.GetFileNameWithoutExtension(physicalPath) + ".html";
                string outputFile = Path.GetDirectoryName(physicalPath) + "\\" + htmlName;
                prsPres.SaveAs(outputFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
                prsPres.Close();
                ppApp.Quit();
                //---------------------------------------------------------------
                //return Path.GetDirectoryName(System.Web.HttpContext.Current.Server.UrlDecode(url)) + "\\" + htmlName;
                string previewFile = Path.GetDirectoryName(serverPath) + "\\" + htmlName;
                res.code    = 1;
                res.message = previewFile;
                return(res);
            }
            catch (Exception ex)
            {
                res.code    = 0;
                res.message = ex.Message;
                return(res);
            }
        }
Exemple #4
0
        private static void SearchFile(string folder)
        {
            Microsoft.Office.Interop.PowerPoint.Application app = null;
            try
            {
                //Fileオブジェクトを作る
                FileInfo target = new FileInfo(folder);

                //PowerPointの新しいインスタンスを作成する
                app = new Microsoft.Office.Interop.PowerPoint.Application();

                //最小化状態で表示する
                app.Visible     = MsoTriState.msoTrue;
                app.WindowState = Microsoft.Office.Interop.PowerPoint.PpWindowState.ppWindowMinimized;

                GetPowerPointData(
                    app.Presentations.Open(target.FullName, MsoTriState.msoFalse,
                                           MsoTriState.msoFalse,
                                           MsoTriState.msoFalse));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
            finally
            {
                //PowerPointを終了する
                if (app != null)
                {
                    app.Quit();
                }
            }
        }
 public Presentation(Size paperSize)
 {
     _powerPoint   = new Microsoft.Office.Interop.PowerPoint.Application();
     _presentation = _powerPoint.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse);
     _presentation.PageSetup.SlideHeight = paperSize.Height;
     _presentation.PageSetup.SlideWidth  = paperSize.Width;
 }
Exemple #6
0
        public static PowerPointExtension GetDefaultPowerPointExtension()
        {
            Microsoft.Office.Interop.PowerPoint.Application appl = new Microsoft.Office.Interop.PowerPoint.Application();

            string sVersion = appl.Version;

            switch (sVersion.ToString())
            {
            case "7.0": return(PowerPointExtension.PPT);

            case "8.0": return(PowerPointExtension.PPT);

            case "9.0": return(PowerPointExtension.PPT);

            case "10.0": return(PowerPointExtension.PPT);

            case "11.0": return(PowerPointExtension.PPT);

            case "12.0": return(PowerPointExtension.PPTX);

            case "14.0": return(PowerPointExtension.PPTX);

            case "15.0": return(PowerPointExtension.PPTX);

            default: return(null);
            }
        }
Exemple #7
0
        /// <summary>
        /// Reads PPT and PPTX file types and extracts the words in each file
        /// Requires: The file path is in ppt or pptx format only
        /// </summary>
        /// <param name="filenameWithPath">path of PPT and PPTX document including filename</param>
        /// <exception cref="PlatformNotSupportedException">Thrown when the file to read is not of supported
        /// presentation format. </exception>
        /// <returns>
        /// A Dictionary where the Key contains the filename and the Value contains the entire wordlist
        /// </returns>
        private static Dictionary <string, List <string> > readPPTFiles(string filenameWithPath)
        {
            Contract.Requires <PlatformNotSupportedException>(System.IO.Path.GetExtension(filenameWithPath).Equals(".ppt") ||
                                                              System.IO.Path.GetExtension(filenameWithPath).Equals(".pptx"));

            List <string> result = new List <string>();
            Dictionary <string, List <string> > listresult = new Dictionary <string, List <string> >();

            Microsoft.Office.Interop.PowerPoint.Application   PowerPoint_App      = new Microsoft.Office.Interop.PowerPoint.Application();
            Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
            Microsoft.Office.Interop.PowerPoint.Presentation  presentation        = multi_presentations.Open(filenameWithPath);
            for (int i = 0; i < presentation.Slides.Count; i++)
            {
                foreach (var item in presentation.Slides[i + 1].Shapes)
                {
                    var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                    if (shape.HasTextFrame == MsoTriState.msoTrue)
                    {
                        if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                        {
                            var    textRange = shape.TextFrame.TextRange;
                            string text      = textRange.Text.ToLower().Trim().ToString();
                            result.AddRange(text.Split(new char[] { ' ', '\n', '\t', '\r' }));
                        }
                    }
                }
            }
            PowerPoint_App.Quit();
            listresult.Add(filenameWithPath, result);
            return(listresult);
        }
Exemple #8
0
        public bool GetCurrentPowepointDocs(out List <string> ppt)
        {
            ppt = new List <string>();
            Microsoft.Office.Interop.PowerPoint.Application PpObj = null;
            try
            {
                PpObj = (Microsoft.Office.Interop.PowerPoint.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Powerpoint.Application");


                Console.WriteLine("Open : " + PpObj.Windows.Count);
                foreach (Microsoft.Office.Interop.PowerPoint.Presentation pp in PpObj.Presentations)
                {
                    Console.WriteLine("Open : " + pp.FullName);
                    ppt.Add(pp.FullName);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                if (PpObj != null)
                {
                    Marshal.ReleaseComObject(PpObj);
                }
            }

            return(true);
        }
        /// <summary>
        /// 调用office的Com组件
        /// </summary>
        /// <param name="pptPath"></param>
        /// <returns></returns>
        private int PPTToImgCom(string pptPath, string imgName)
        {
            var    app         = new Microsoft.Office.Interop.PowerPoint.Application();
            string paramSource = Server.MapPath("~/file/ppt/") + pptPath;
            string imgPath     = "~/file/img/" + imgName;

            CheckDirect(Server.MapPath(imgPath));
            string paramTarget = Server.MapPath(imgPath);
            var    ppt         = app.Presentations.Open(paramSource, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            var    index       = 0;
            var    fileName    = System.IO.Path.GetFileNameWithoutExtension(pptPath);

            foreach (Microsoft.Office.Interop.PowerPoint.Slide slid in ppt.Slides)
            {
                ++index;
                //设置图片大小
                slid.Export(Path.Combine(paramTarget, string.Format("{0}.jpg", index)), "jpg", 800, 600);

                //根据屏幕尺寸。设置图片大小
                //slid.Export(imgPath+string.Format("page{0}.jpg",index.ToString()), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
            }
            //释放资源
            ppt.Close();
            app.Quit();
            GC.Collect();
            return(index);
        }
        /// <summary>
        /// Test to see if PPT is installed on this system.
        /// After we've checked once, just return the same value again without rechecking.
        /// </summary>
        /// <returns></returns>
        public static bool CheckPptIsInstalled()
        {
            if (checkedPptInstalled)
            {
                return(pptInstalled);
            }

            bool ret = true;

            Microsoft.Office.Interop.PowerPoint.Application ppApp;
            try
            {
                ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
            }
            catch
            {
                ret = false;
            }
            finally
            {
                ppApp = null;
            }

            checkedPptInstalled = true;
            pptInstalled        = ret;
            return(ret);
        }
Exemple #11
0
    protected override void printWorker()
    {
        try
        {
            isPrinting       = true;
            officePowerPoint = new Microsoft.Office.Interop.PowerPoint.Application();
            officePowerPoint.DisplayAlerts = Microsoft.Office.Interop.PowerPoint.PpAlertLevel.ppAlertsNone;
            Microsoft.Office.Interop.PowerPoint.Presentation doc = null;
            doc = officePowerPoint.Presentations.Open(
                filename,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoFalse,
                Microsoft.Office.Core.MsoTriState.msoFalse);
            doc.PrintOptions.ActivePrinter     = printer;
            doc.PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse;
            doc.PrintOptions.OutputType        = Microsoft.Office.Interop.PowerPoint.PpPrintOutputType.ppPrintOutputSlides;
            doc.PrintOut();
            System.Threading.Thread.Sleep(500);
            doc.Close();
            Marshal.FinalReleaseComObject(doc);
            doc           = null;
            workerPrintOk = true;
            isPrinting    = true;
        }
        catch (System.Exception ex)
        {
            isPrinting = false;

            Logging.Log("Unable to print PowerPoint file " + filename + ". Exception: " + ex.Message, Logging.LogLevel.Error);
            workerPrintOk = false;
        }
    }
Exemple #12
0
        /// <summary>把Word文件转换成为PDF格式文件</summary>   
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PowerPointToHtml(string sourcePath, string targetPath)
        {
            bool result = false;

            try
            {
                //Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.;
                Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Core.MsoTriState m1 = new MsoTriState();
                Microsoft.Office.Core.MsoTriState m2 = new MsoTriState();
                Microsoft.Office.Core.MsoTriState m3 = new MsoTriState();
                Microsoft.Office.Interop.PowerPoint.Presentation pp = ppt.Presentations.Open(sourcePath, m1, m2, m3);
                pp.SaveAs(targetPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, Microsoft.Office.Core.MsoTriState.msoTriStateMixed);
                pp.Close();
                ppt.Quit();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
                return(false);
            }
        }
        /// <summary>
        ///     The convert to pptx.
        /// </summary>
        /// <param name="fullPath">The full path.</param>
        /// <param name="targetLanguage">The target language.</param>
        /// <returns>
        ///     The System.String.
        /// </returns>
        private static string ConvertToPptx(string fullPath, string targetLanguage)
        {
            LoggingManager.LogMessage("Converting the document " + fullPath + " from ppt to pptx.");

            object file2 = GetOutputDocumentFullName(fullPath, targetLanguage);

            Microsoft.Office.Interop.PowerPoint.Application powerPointApp =
                new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                Microsoft.Office.Interop.PowerPoint.Presentation presentation =
                    powerPointApp.Presentations.Open(
                        fullPath,
                        MsoTriState.msoFalse,
                        MsoTriState.msoFalse,
                        MsoTriState.msoFalse);

                presentation.SaveAs(
                    file2.ToString(),
                    Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
                    MsoTriState.msoTriStateMixed);
                presentation.Close();
            }
            finally
            {
                powerPointApp.Quit();
            }

            LoggingManager.LogMessage("Converted the document " + fullPath + " from ppt to pptx.");
            return(file2.ToString());
        }
        private void buttonSlideShowFullScreen_Click(object sender, RibbonControlEventArgs e)
        {
            try
            {
                thisApplication = Globals.ThisAddIn.Application;
                showWindow = thisApplication.ActivePresentation.SlideShowSettings.Run();

                // If leap is not available, just run slideshow and quit
                while (true)
                {
                    // LeapMotion이 꽂혀 있으면 밖으로 나감
                    if (setupLeapMotion())
                        break;

                    // 만약에 Retry를 No 하면, 걍 종료
                    if (MessageBox.Show("Leap Motion is not connected. Check the connection.", "Leap Motion is missing.", MessageBoxButtons.RetryCancel) == DialogResult.Cancel)
                        return;
                }
                thisApplication.SlideShowEnd += new Microsoft.Office.Interop.PowerPoint.EApplication_SlideShowEndEventHandler(thisApplication_SlideShowEnd);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace);
            }
        }
        public static void PptToHtmlFile(string PptFilePath)
        {
            //获得html文件名

            string htmlFileName = PptFilePath.Substring(0, PptFilePath.LastIndexOf(".")) + ".html";

            Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();

            Microsoft.Office.Interop.PowerPoint.Presentation pptFile = null;

            try
            {
                //打开一个ppt文件

                pptFile = ppt.Presentations.Open(PptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue,

                                                 Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);

                //转换成html格式

                pptFile.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,

                               Microsoft.Office.Core.MsoTriState.msoCTrue);
            }

            finally
            {
                if (pptFile != null)
                {
                    pptFile.Close();
                }
                ppt.Quit();
                GC.Collect();
            }
        }
Exemple #16
0
 protected override void Given()
 {
     this.slideManager       = new SlideManager();
     this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
     this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);
     this.initialSlideCount  = this.slideManager.GetSlideCount(this.presentationHandle);
 }
Exemple #17
0
        private void btnConvertAll_Click(object sender, EventArgs e)
        {
            progressBar1.Visible = true;
            progressBar1.Maximum = listBoxFiles.Items.Count;
            progressBar1.Step    = 1;
            Microsoft.Office.Interop.PowerPoint.Application pptApp = new Microsoft.Office.Interop.PowerPoint.Application();
            foreach (object logListItem in listBoxFiles.Items)
            {
                progressBar1.PerformStep();
                this.Refresh();

                string strLogName      = logListItem.ToString();
                string strFullFilePath = textBoxFolder.Text + "\\" + strLogName;

                if (File.Exists(strFullFilePath + ".ppt"))
                {
                    Microsoft.Office.Interop.PowerPoint.Presentation pptPresentation = pptApp.Presentations.Open(strFullFilePath + ".ppt", MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                    pptPresentation.SaveAs(strFullFilePath + ".pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsOpenXMLPicturePresentation);
                    pptPresentation.Close();
                }
            }
            pptApp.Quit();
            progressBar1.Visible = false;
        }
Exemple #18
0
        static void ppt2pdf(string inputPath, string outputPath)
        {
            if (!File.Exists(inputPath))
            {
                throw new FileNotFoundException(string.Format("The specified file {0} does not exist.", inputPath), inputPath);
            }

            try
            {
                Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();

                app.Presentations.Open(
                    inputPath,
                    Microsoft.Office.Core.MsoTriState.msoFalse,
                    Microsoft.Office.Core.MsoTriState.msoFalse,
                    Microsoft.Office.Core.MsoTriState.msoFalse)
                .SaveAs(
                    outputPath,
                    Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF);
                app.Quit();
            }
            catch (Exception e)
            {
                throw new Exception(string.Format("Unable to convert {0} to {1}", inputPath, outputPath), e);
            }
        }
Exemple #19
0
        protected override void Given()
        {
            this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
            this.slideManager       = new SlideManager();
            this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);

            // Add some slides to the presentation
            this.slideHandle = this.slideManager.AddSlideToEnd(this.presentationHandle);
            this.slideHandle = this.slideManager.AddSlideToEnd(this.presentationHandle);
            this.slideHandle = this.slideManager.AddSlideToEnd(this.presentationHandle);

            // Add some shapes to slides
            this.shapesHandler.DrawShape(
                this.presentationHandle.Slides[1],
                MsoAutoShapeType.msoShapeRectangle,
                100f,
                100f,
                100f,
                100f);

            this.shapesHandler.DrawShape(
                this.presentationHandle.Slides[2],
                MsoAutoShapeType.msoShapeRectangle,
                100f,
                100f,
                100f,
                100f);
        }
 public CreateResultView()
 {
     InitializeComponent();
     _app = Globals.ThisAddIn.Application;
     ValidateResultSlide();
     FillQuestionsList();
     SetInitialValues();
 }
Exemple #21
0
 private void allocPowerPoint()
 {
     if (avaPoawrPoint)
     {
         pptApp  = new Microsoft.Office.Interop.PowerPoint.Application();
         pptPres = pptApp.Presentations;
     }
 }
Exemple #22
0
 protected override void Given()
 {
     this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
     this.slideManager       = new SlideManager();
     this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);
     this.slideHandle        = this.slideManager.AddSlideToEnd(this.presentationHandle);
     this.shapesHandler      = new ShapesManager();
 }
        public Office文件显示(string str, CE_SystemFileType documentType)
        {
            InitializeComponent();

            try
            {
                oframe.Open(@str);

                oframe.Menubar  = false;
                oframe.Titlebar = false;
                oframe.Toolbars = false;

                this.oframe.ProtectDoc(1, 2, "pwd");

                switch (documentType)
                {
                case CE_SystemFileType.Word:

                    Microsoft.Office.Interop.Word.Document    wordDoc = (Microsoft.Office.Interop.Word.Document)oframe.ActiveDocument;
                    Microsoft.Office.Interop.Word.Application wordApp = wordDoc.Application;
                    break;

                case CE_SystemFileType.Excel:

                    Microsoft.Office.Interop.Excel.Workbook    excelDoc = (Microsoft.Office.Interop.Excel.Workbook)oframe.ActiveDocument;
                    Microsoft.Office.Interop.Excel.Application excelApp = excelDoc.Application;

                    excelApp.OnKey("^x", "");
                    excelApp.OnKey("^c", "");
                    excelApp.OnKey("^v", "");
                    break;

                case CE_SystemFileType.PPT:

                    Microsoft.Office.Interop.PowerPoint._Presentation pptDoc =
                        (Microsoft.Office.Interop.PowerPoint._Presentation)oframe.ActiveDocument;
                    Microsoft.Office.Interop.PowerPoint.Application pptApp = pptDoc.Application;

                    keybd_event((byte)Keys.F5, 0, 0, 0);
                    keybd_event((byte)Keys.F5, 0, 2, 0);

                    break;

                case CE_SystemFileType.PDF:
                    break;

                case CE_SystemFileType.Miss:
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemple #24
0
 public void Compare(string orginal, string target)
 {
     Microsoft.Office.Interop.PowerPoint.Application powerPoint = new Microsoft.Office.Interop.PowerPoint.Application {
         Visible = MsoTriState.msoCTrue
     };
     Microsoft.Office.Interop.PowerPoint.Presentation presentation = powerPoint.Presentations.Open(orginal);
     presentation.Merge(target);
     powerPoint.ActivePresentation.Saved = MsoTriState.msoCTrue;
 }
 public void OpenPowerPoint()
 {
     powerpoint         = new Microsoft.Office.Interop.PowerPoint.Application();
     powerpoint.Visible = MsoTriState.msoTrue;
     //Prevent Office Assistant from displaying alert messages:
     bAssistantOn            = powerpoint.Assistant.On;
     powerpoint.Assistant.On = false;
     presentationSet         = powerpoint.Presentations;
 }
Exemple #26
0
 protected override void Given()
 {
     this.slideManager       = new SlideManager();
     this.powerpointHandle   = new Microsoft.Office.Interop.PowerPoint.Application();
     this.presentationHandle = this.SUT.CreatePowerPointPresentation(this.powerpointHandle, false);
     this.slideHandle        = this.slideManager.AddSlideToEnd(this.presentationHandle);
     this.shapesHandler      = new Shapes();
     this.returnedShape      = this.shapesHandler.AddTextBoxToSlide(this.slideHandle, MsoTextOrientation.msoTextOrientationHorizontal, 100f, 100f, 100f, 100f);
 }
Exemple #27
0
        //private Boolean CompareGroupPerms()
        //{
        //    Boolean compare = false;
        //    string fileId = GetFileId("Excel Schedule.xlsx");
        //    List<string> groupId = GetGroupId("4");
        //    //CheckWriteOnlyGroup("4", "Excel Schedule.xlsx");
        //    for (int i = 0; i < groupId.Count; i++)
        //    {
        //        if (CheckWriteOnlyGroup(fileId, groupId[i]) == "True")
        //        {
        //            compare = true;
        //        }
        //        else
        //        {
        //            compare = false;
        //        }
        //    }
        //}

        private void CheckPpt()
        {
            string      fileName = @"C:\Users\Solomon\Documents\TEST\trided.pptx";
            MsoTriState readOnly = MsoTriState.msoFalse;
            object      missing  = System.Reflection.Missing.Value;

            Microsoft.Office.Interop.PowerPoint.Application applicationPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            applicationPPT.Presentations.Open(fileName, readOnly, MsoTriState.msoTrue, MsoTriState.msoTrue);
        }
Exemple #28
0
 protected override void Initialize()
 {
     base.Initialize();
     this.Application  = this.GetHostItem <Microsoft.Office.Interop.PowerPoint.Application>(typeof(Microsoft.Office.Interop.PowerPoint.Application), "Application");
     Globals.ThisAddIn = this;
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
 }
 public void Initialised(object context)
 {
     presentation = (Microsoft.Office.Interop.PowerPoint.Presentation)context;
     if (presentation == null)
     {
         return;
     }
     application = presentation.Application;
     application.PresentationNewSlide += ApplicationOnPresentationNewSlide;
 }
Exemple #30
0
 private void createSlideFromTemplate()
 {
     //Create a new presentation based on a template.
     objApp         = new Microsoft.Office.Interop.PowerPoint.Application();
     objApp.Visible = MsoTriState.msoTrue;
     objPresSet     = objApp.Presentations;
     objPres        = objPresSet.Open(strTemplate,
                                      MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
     objSlides = objPres.Slides;
 }
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            PowerPointApp = Globals.ThisAddIn.Application;

            SharedApp.HostApp = Globals.ThisAddIn.Application;
            SharedApp.InitAppTaskPanes(ref this.CustomTaskPanes);
            SharedApp.AppTaskPanes.CreateTaskpaneInstance();

            PowerPointApp.AfterPresentationOpen += new Microsoft.Office.Interop.PowerPoint.EApplication_AfterPresentationOpenEventHandler(PowerPoint_AfterOpen);
        }
 protected override void Initialize() {
     base.Initialize();
     this.Application = this.GetHostItem<Microsoft.Office.Interop.PowerPoint.Application>(typeof(Microsoft.Office.Interop.PowerPoint.Application), "Application");
     Globals.ThisAddIn = this;
     global::System.Windows.Forms.Application.EnableVisualStyles();
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
 }
        /// <summary>
           /// ppt convert to html
           /// </summary>
           /// <param name="path">要转换的文档的路径</param>
           /// <param name="savePath">转换成的html的保存路径</param>
           /// <param name="wordFileName">转换后html文件的名字</param>
        public static void PPTToHtml(string path, string savePath, string wordFileName)
        {
            Microsoft.Office.Interop.PowerPoint.Application ppApp = new Microsoft.Office.Interop.PowerPoint.Application();
            string strSourceFile      = path;
            string strDestinationFile = savePath + wordFileName + ".html";

            Microsoft.Office.Interop.PowerPoint.Presentation prsPres = ppApp.Presentations.Open(strSourceFile, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse);
            prsPres.SaveAs(strDestinationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML, MsoTriState.msoTrue);
            prsPres.Close();
            ppApp.Quit();
        }
 public void Initialize() {
     this.HostItemHost = ((Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider)(this.RuntimeCallback.GetService(typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.IHostItemProvider))));
     this.DataHost = ((Microsoft.VisualStudio.Tools.Applications.Runtime.ICachedDataProvider)(this.RuntimeCallback.GetService(typeof(Microsoft.VisualStudio.Tools.Applications.Runtime.ICachedDataProvider))));
     object hostObject = null;
     this.HostItemHost.GetHostObject("Microsoft.Office.Interop.PowerPoint.Application", "Application", out hostObject);
     this.Application = ((Microsoft.Office.Interop.PowerPoint.Application)(hostObject));
     Globals.ThisAddIn = this;
     System.Windows.Forms.Application.EnableVisualStyles();
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
     this.BeginInitialization();
 }
        public static void close()
        {
            if (Ppt != null)
            {
                Ppt.Close();
                Ppt = null;
            }

            if (App != null)
            {
                App.Quit();
                App = null;
            }
        }
        public static void PrintFileAsXps(string path, int index, int total)
        {
            // Avoid Quit if already running.
            bool appAlreadyRunning = System.Diagnostics.Process.GetProcessesByName("powerpnt").Length > 0;

            // Create/get instance of MS PowerPoint.
            // Do it once per file to avoid out-of-memory issues or crashes to due memory fragmentation, etc.
            Console.WriteLine("Starting MS PowerPoint ...");
            var app = new MSOInterop.PowerPoint.Application();

            // Open presentation.
            MSOInterop.PowerPoint._Presentation pptFile;

            var fileInfo = new FileInfo(path);
            Console.WriteLine($"Opening {Path.GetFileName(path)} ({(double)fileInfo.Length / 1024 / 1024:0.##} MB) {index}/{total} ...");
            pptFile = app.Presentations.Open(path,
                                             WithWindow: MSOCore.MsoTriState.msoFalse); // Don't show window.

            // Set options.
            SetPrintOptions(pptFile);

            // Delete if exists.
            DeleteIfExists(pptFile);

            // Print.
            Console.WriteLine($"Printing ...");
            pptFile.PrintOut(PrintToFile: pptFile.FullName.Replace(".pptx", ".xps"));

            // Close file.
            pptFile.Close();
            Marshal.ReleaseComObject(pptFile);
            pptFile = null;

            // Quit app.
            if (!appAlreadyRunning)
            {
                app.Quit();
            }

            // Force process to exit.
            Marshal.ReleaseComObject(app);
            app = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }
        private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var pp = new Microsoft.Office.Interop.PowerPoint.Application();
                int index = 0;

                if (type.Equals("ppt"))
                {
                    var ppt = pp.Presentations.Open(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                    foreach (Microsoft.Office.Interop.PowerPoint.Slide s in ppt.Slides)
                    {
                        s.Export(Path.Combine(outPath, string.Format("{0}{1}.jpg", fileName, index)), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                        index++;
                    }

                    ppt.Close();
                }
                else if (type.Equals("pptx"))
                {
                    var ppt = pp.Presentations.Open2007(filePath, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                    foreach (Microsoft.Office.Interop.PowerPoint.Slide s in ppt.Slides)
                    {
                        s.Export(Path.Combine(outPath, string.Format("{0}{1}.jpg", fileName, index)), "jpg", Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
                        index++;
                    }

                    ppt.Close();
                }
            }
            catch (NullReferenceException ex)
            {
            }
            finally
            {
                type = string.Empty;
                filePath = string.Empty;
                fileName = string.Empty;
                outPath = string.Empty;
            }
        }
        public static void LoadPowerPoint(String filePath)
        {
            if(filePath == null || filePath == ""){
                return;
            }
            FilePath = filePath;
            App = new Microsoft.Office.Interop.PowerPoint.Application();
            App.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;

            Ppt = App.Presentations.Open(filePath,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoTrue,
                Microsoft.Office.Core.MsoTriState.msoTrue);

            slideIndex = new int[Ppt.Slides.Count];
            for (int i = 0; i < slideIndex.Length; i++)
            {
                slideIndex[i] = i + 1;
            }
        }
        public void CopyTemplateToPresentation(string presentationFileTemplate, string presentationFile, BackgroundWorker bckgW)
        {
            try
            {
                var app = new Microsoft.Office.Interop.PowerPoint.Application();
                var pres = app.Presentations;
                var pptfile = pres.Open(presentationFileTemplate, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
                pptfile.SaveCopyAs(presentationFile, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue);

            }
            catch (Exception ex)
            {
                AddToLog("Problem with saving PPTM to PPTX. " + ex.Message);
                MessageBox.Show("Powerpoint template problem. " + ex.Message);
            }
            bckgW.ReportProgress(40);
            //Thread.Sleep(1000);
            var file = new FileInfo(presentationFile);
            while (IsFileLocked(file))
            { }
            bckgW.ReportProgress(50);
        }
        public static void PrintDiscountCoupon(string companyName, string discountProductName, string discountValueOnProduct)
        {
            int copiesToPrint = 1;
            string printTemplateFileName = @"\Assets\Docs\PrinterReceipt.pptx";
            string qrCodeImageName = @"\Assets\Images\QREncode.jpg";
            string printFileName = @"\Assets\Docs\printReceipt.pptx";
            string printTemplateFilePath = Helper.GetAssetURI(printTemplateFileName);
            string qrCodeImagepath = Helper.GetAssetURI(qrCodeImageName);
            string printReceiptFilePath = Helper.GetAssetURI(printFileName);
            Microsoft.Office.Interop.PowerPoint.Presentation work = null;
            Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                if (File.Exists(printReceiptFilePath))
                {
                    File.Delete(printReceiptFilePath);
                }
                if (File.Exists(qrCodeImagepath))
                {
                    File.Delete(qrCodeImagepath);
                }

                Microsoft.Office.Interop.PowerPoint.Presentations presprint = app.Presentations;
                work = presprint.Open(printTemplateFilePath, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);
                work.PrintOptions.PrintInBackground = Microsoft.Office.Core.MsoTriState.msoFalse;
                Microsoft.Office.Interop.PowerPoint.Slide slide = work.Slides[1];
                foreach (var item in slide.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;
                            if (text.Contains("10%"))
                            {
                                text = text.Replace("10", discountValueOnProduct);
                                shape.TextFrame.TextRange.Text = text;
                            }
                            else if (text.Contains("Microsoft"))
                            {
                                text = text.Replace("Microsoft", companyName);
                                shape.TextFrame.TextRange.Text = text;
                            }
                            else if (text.Contains("Windows Phone 8"))
                            {
                                text = text.Replace("Windows Phone 8", discountProductName);
                                shape.TextFrame.TextRange.Text = text;
                            }

                        }
                    }
                    else
                    {
                        if (shape.Name.ToString() == "Picture 2")
                        {
                            shape.Delete();
                            //Add QRCode to print
                            RippleCommonUtilities.HelperMethods.GenerateQRCode("http://projectripple.azurewebsites.net/Ripple.aspx", qrCodeImagepath);
                            slide.Shapes.AddPicture(qrCodeImagepath, MsoTriState.msoFalse, MsoTriState.msoTrue, 560, 90, 80, 80);
                        }
                    }
                }

                work.SaveAs(printReceiptFilePath);
                work.PrintOut();
                work.Close();
                app.Quit();

                //delete the PrintReceipt File
                File.Delete(printReceiptFilePath);
                //Delete the QRCOde image
                File.Delete(qrCodeImagepath);
            }
            catch (System.Exception ex)
            {
                work.Close();
                app.Quit();
                //delete the PrintReceipt File
                File.Delete(printReceiptFilePath);
                //Delete the QRCOde image
                File.Delete(qrCodeImagepath);
                RippleCommonUtilities.LoggingHelper.LogTrace(1, "Went wrong in  Print Discount Coupon at Screen side: {0}", ex.Message);
            }
        }
Exemple #41
0
        public void TestCleanToWithPPTApp()
        {
            return;

			Microsoft.Office.Interop.PowerPoint.Application app = new Microsoft.Office.Interop.PowerPoint.Application();

            try
            {
                AppCountMonitor monitor = new AppCountMonitor("powerpnt");
                string testDoc = TestUtils.TestFileUtils.MakeRootPathAbsolute(@"Projects\Workshare.API\Workshare.API.Tests\TestDocs\test.ppt");
                using (TempFile tf = new TempFile(testDoc))
                {
                    using (TempFile dest = new TempFile())
                    {
                        File.Delete(dest.FilePath);
                        string initialHash = tf.MD5Sum;
                        IOfficeCleaner c = new OfficeCleaner();
                        c.CleanFileTo(tf.FilePath, dest.FilePath, app);
                        Assert.IsTrue(File.Exists(dest.FilePath), "We expected the dest file to be created");
                        string newHash = dest.MD5Sum;
                        Assert.AreNotEqual(initialHash, newHash, "We expected the Cleanion to change the file contents");
                    }
                }
                Assert.IsFalse(monitor.SeenMoreInstances(), "Additional instances of PowerPoint were created during the test run - that means it didn't use the provided instance");
            }
            finally
            {
                object oFalse = false;
                app.Quit();
				Marshal.ReleaseComObject(app);
            }
        }
 private void createSlideFromTemplate()
 {
     //Create a new presentation based on a template.
     objApp = new Microsoft.Office.Interop.PowerPoint.Application();
     objApp.Visible = MsoTriState.msoTrue;
     objPresSet = objApp.Presentations;
     objPres = objPresSet.Open(strTemplate,
         MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
     objSlides = objPres.Slides;
 }
        public static void PptToHtmlFile(string PptFilePath)
        {
            //获得html文件名

            string htmlFileName = PptFilePath.Substring(0, PptFilePath.LastIndexOf(".")) + ".html";

            Microsoft.Office.Interop.PowerPoint.Application ppt = new Microsoft.Office.Interop.PowerPoint.Application();

            Microsoft.Office.Interop.PowerPoint.Presentation pptFile = null;

            try
            {

                //打开一个ppt文件

                pptFile = ppt.Presentations.Open(PptFilePath, Microsoft.Office.Core.MsoTriState.msoTrue,

                    Microsoft.Office.Core.MsoTriState.msoCTrue, Microsoft.Office.Core.MsoTriState.msoFalse);

                //转换成html格式

                pptFile.SaveAs(htmlFileName, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsHTML,

                    Microsoft.Office.Core.MsoTriState.msoCTrue);

            }

            finally
            {

                if (pptFile != null)
                {

                    pptFile.Close();

                }
                ppt.Quit();
                GC.Collect();
            }
        }
        //==================================
        public string ConvertHtmlToPpt(int projectId)
        {
            string pptFileName = string.Empty;
            try
            {
                ProjectSummaryDetailModel objSummaryModel = new ProjectSummaryDetailModel();
                objSummaryModel = ProjectSummary.GetProjectSummaryDetail(projectId);

                string pptFilePath = string.Empty;
                string htmlFilePath = string.Empty;

                StringWriter sw = new StringWriter();

                // Create new PPTX file for the attachment purposes.

                pptFileName = projectId + "ProjectName" + Guid.NewGuid().ToString().Substring(0, 6);
                pptFilePath = Server.MapPath("~/Temp/" + pptFileName);

                Microsoft.Office.Interop.PowerPoint.Application powerPointApp = new Microsoft.Office.Interop.PowerPoint.Application();

                // VPS 28-10-2015

                powerPointApp.Visible = MsoTriState.msoTrue;
                Microsoft.Office.Interop.PowerPoint.Application PowerPoint_App = new Microsoft.Office.Interop.PowerPoint.Application();
                Microsoft.Office.Interop.PowerPoint.Presentations multi_presentations = PowerPoint_App.Presentations;
                Microsoft.Office.Interop.PowerPoint.Presentation presentation = multi_presentations.Open(Server.MapPath("~/Temp/Template/Slide_Template.pptx"), MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

                // Copy The Master presentation to the New presentation

                // Now open this new presentation slide and alter this with dynamic data

                for (int i = 0; i < presentation.Slides.Count; i++)
                {
                    foreach (var item in presentation.Slides[i + 1].Shapes)
                    {
                        var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;
                        if (shape.HasTable == MsoTriState.msoTrue)
                        {
                            int columnCount = shape.Table.Columns.Count;
                            if (columnCount == 13) // Detect if this is the duration Table
                            {
                                if (objSummaryModel.ProjectDurationList != null && objSummaryModel.ProjectDurationList.Count > 0)
                                {
                                    // Find single column Width
                                    var column1 = shape.Table.Columns[1];
                                    float column1Width = column1.Width;
                                    float tableHeight = shape.Height;
                                    // Calculate Table Width [Multiply with 7 as initial 7 columns have proper design]
                                    float tableWidth = column1Width * 13;

                                    // Get Total Records
                                    int recordsCount = objSummaryModel.ProjectDurationList.Count;
                                    if (recordsCount < 13)
                                    {
                                        for (int lastColIndex = columnCount; lastColIndex >= recordsCount + 1; lastColIndex--)
                                        {
                                            var colToDelete = shape.Table.Columns[lastColIndex];
                                            colToDelete.Delete();
                                        }
                                    }
                                    // Get new Width of Each Columns;
                                    float newColsWidth = tableWidth / recordsCount;

                                    for (int rec = 0; rec <= recordsCount - 1; rec++)
                                    {
                                        //shape.Table.Columns.Add(-1);
                                        var column = shape.Table.Columns[rec + 1];//[1];
                                        column.Width = newColsWidth;
                                        var cell = shape.Table.Cell(1, rec + 1);//shape.Table.Columns.Count);
                                        var projectDuration = objSummaryModel.ProjectDurationList.ElementAt(rec);
                                        cell.Shape.TextFrame.TextRange.Text = projectDuration.Title;
                                    }
                                    // Delete the default column
                                    //column1.Delete();
                                    shape.Width = tableWidth;
                                    shape.Height = tableHeight;
                                }
                            }
                        }

                        if (shape.HasTextFrame == MsoTriState.msoTrue)
                        {
                            if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                            {
                                var textRange = shape.TextFrame.TextRange;
                                var text = textRange.Text;

                                if (text.IndexOf("Color_O") != -1)
                                {
                                    shape.TextFrame.TextRange.Replace("Color_O", "");//objSummaryModel.OverallStatusId.ToString());
                                    FillShapeColor(shape, objSummaryModel.OverallStatusId);
                                }

                                if (text.IndexOf("Color_Sp") != -1)
                                {
                                    shape.TextFrame.TextRange.Replace("Color_Sp", "");//objSummaryModel.ScopeId.ToString());
                                    FillShapeColor(shape, objSummaryModel.ScopeId);
                                }

                                if (text.IndexOf("Color_Sc") != -1)
                                {
                                    shape.TextFrame.TextRange.Replace("Color_Sc", "");//objSummaryModel.ScheduleId.ToString());
                                    FillShapeColor(shape, objSummaryModel.ScheduleId);
                                }

                                if (text.IndexOf("Color_R") != -1)
                                {
                                    shape.TextFrame.TextRange.Replace("Color_R", "");//objSummaryModel.ResourceId.ToString());
                                    FillShapeColor(shape, objSummaryModel.ResourceId);
                                }

                                if (text.IndexOf("Color_F") != -1)
                                {
                                    shape.TextFrame.TextRange.Replace("Color_F", "");//objSummaryModel.FinancialId.ToString());
                                    FillShapeColor(shape, objSummaryModel.FinancialId);
                                }

                                if (text.IndexOf("Slide_date") != -1)
                                    shape.TextFrame.TextRange.Replace("Slide_date", DateTime.Now.ToString("MM/dd/yyyy"));

                                if (text.IndexOf("Project_Title") != -1)
                                    shape.TextFrame.TextRange.Replace("Project_Title", objSummaryModel.ProjectName);

                                if (text.IndexOf("Project_Owner") != -1)
                                    shape.TextFrame.TextRange.Replace("Project_Owner", objSummaryModel.AnthemOwner);

                                if (text.IndexOf("Project_CoOwner") != -1)
                                    shape.TextFrame.TextRange.Replace("Project_CoOwner", objSummaryModel.PartnerName);

                                if (text.IndexOf("start_Date") != -1)
                                    shape.TextFrame.TextRange.Replace("start_Date", objSummaryModel.ProjectStartDateString);

                                if (text.IndexOf("end_Date") != -1)
                                    shape.TextFrame.TextRange.Replace("end_Date", objSummaryModel.ProjectEndDateString);

                                if (text.IndexOf("perc_Completed") != -1)
                                    shape.TextFrame.TextRange.Replace("perc_Completed", Convert.ToString(objSummaryModel.ProjectComplete));

                                if (text.IndexOf("project_desc_And_Buss_Value") != -1)
                                    shape.TextFrame.TextRange.Replace("project_desc_And_Buss_Value", (!String.IsNullOrEmpty(objSummaryModel.ProjectDescription) ? ReplaceHtmlTags(objSummaryModel.ProjectDescription) : ""));

                                if (text.IndexOf("Project_ExecutionSummary") != -1)
                                    shape.TextFrame.TextRange.Replace("Project_ExecutionSummary", (!String.IsNullOrEmpty(objSummaryModel.ProjectExecutiveSummary) ? ReplaceHtmlTags(objSummaryModel.ProjectExecutiveSummary) : ""));//"The Server Standard Platforms Program provides standard server specifications and pricing in support of:\n Technology Strategies and Planning roadmaps\nInfrastructure Lifecycle Management objectives\nIT Finance Cost Recovery goals\nDemand Management targets\nData Center Services platform Build best practices\nData Center Services platform Run fault isolation/problem determination processes\n\nEssential in providing this support is the Standard Platforms Offerings Quick Reference Guide (SPO QRG). This set of documentation maps  server, operating system, middleware, and storage speculations to costs.");

                                if (text.IndexOf("Project_accomplishments") != -1)
                                    shape.TextFrame.TextRange.Replace("Project_accomplishments", (!String.IsNullOrEmpty(objSummaryModel.ProjectAccomplishments) ? ReplaceHtmlTags(objSummaryModel.ProjectAccomplishments) : ""));//"SPO QRG V09.02.20 published on schedule\n Updated IBM Contract Rates\nEnhanced SPO Cost Codes with OS & Middleware version\nRe-designed Engineering Extract for “One Way Ordering\"");

                                if (text.IndexOf("Project_Issues") != -1)
                                    shape.TextFrame.TextRange.Replace("Project_Issues", (!String.IsNullOrEmpty(objSummaryModel.ProjectKeyRiskIssues) ? ReplaceHtmlTags(objSummaryModel.ProjectKeyRiskIssues) : ""));// "Current documentation tool (Excel) may not be adequate to manage future requirements:\nIBM/ANTM 2015 contract added Harrisonburg and Virginia Beach to data center  options\nIBM/ANTM 2015 contract added IBM hosted cloud based services options\nService Now catalog integration requirements may be difficult to implement and maintain\nServer automated configuration tools integration requirements may be difficult to implement and maintain");

                                if (text.IndexOf("Funding_Ask") != -1)
                                    shape.TextFrame.TextRange.Replace("Funding_Ask", (!String.IsNullOrEmpty(objSummaryModel.ProjectFundingAsk) ? ReplaceHtmlTags(objSummaryModel.ProjectFundingAsk) : ""));// "Capital");

                                if (text.IndexOf("direction_Needed") != -1)
                                    shape.TextFrame.TextRange.Replace("direction_Needed", (!String.IsNullOrEmpty(objSummaryModel.ProjectDirection) ? ReplaceHtmlTags(objSummaryModel.ProjectDirection) : ""));// "Approval to develop a database SPO Catalog tool to replace the SPO Quick Reference Guide Excel workbook.");
                            }
                        }
                    }
                }

                for (int i = 0; i < presentation.Slides.Count; i++)
                {
                    foreach (var item in presentation.Slides[i + 1].Shapes)
                    {
                        var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;

                        if (shape.HasTextFrame == MsoTriState.msoTrue)
                        {
                            if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                            {
                                var textRange = shape.TextFrame.TextRange;
                                var text = textRange.Text;

                                if (objSummaryModel.ProjectDurationList != null && objSummaryModel.ProjectDurationList.Count > 0)
                                {
                                    int recordsCount = objSummaryModel.ProjectDurationList.Count;
                                    for (int rec = 0; rec <= recordsCount - 1; rec++)
                                    {
                                        var projectDuration = objSummaryModel.ProjectDurationList.ElementAt(rec);
                                        if (projectDuration.MileStoneList != null && projectDuration.MileStoneList.Count > 0)
                                        {
                                            int j = 0;
                                            foreach (var milestone in projectDuration.MileStoneList)
                                            {
                                                if (text == "_" + Convert.ToString(rec) + Convert.ToString(j) + "dsc")
                                                {
                                                    Microsoft.Office.Interop.PowerPoint.Slide slide = presentation.Slides[1];
                                                    switch (milestone.MilestoneStatus)
                                                    {
                                                        case 1:
                                                            {
                                                                Microsoft.Office.Interop.PowerPoint.Shape pic = slide.Shapes.AddPicture(Server.MapPath("~/Temp/Template/1.jpg"), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, 10, 10);
                                                                break;
                                                            }
                                                        case 2:
                                                            {

                                                                Microsoft.Office.Interop.PowerPoint.Shape pic = slide.Shapes.AddPicture(Server.MapPath("~/Temp/Template/2.jpg"), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, 10, 10);
                                                                break;
                                                            }
                                                        case 3:
                                                            {
                                                                Microsoft.Office.Interop.PowerPoint.Shape pic = slide.Shapes.AddPicture(Server.MapPath("~/Temp/Template/3.jpg"), Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, 10, 10);
                                                                break;
                                                            }
                                                    }
                                                    textRange.Text = "  " + milestone.Title;
                                                }
                                                j++;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Remove all unused shapes
                for (int i = 0; i < presentation.Slides.Count; i++)
                {
                    foreach (var item in presentation.Slides[i + 1].Shapes)
                    {
                        var shape = (Microsoft.Office.Interop.PowerPoint.Shape)item;

                        if (shape.HasTextFrame == MsoTriState.msoTrue)
                        {
                            if (shape.TextFrame.HasText == MsoTriState.msoTrue)
                            {
                                var textRange = shape.TextFrame.TextRange;
                                var text = textRange.Text;

                                if (text.IndexOf("dsc") != -1)
                                {
                                    shape.TextFrame.DeleteText();
                                }
                            }
                        }
                    }
                }

                presentation.SaveAs(pptFilePath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, MsoTriState.msoTrue);
                presentation.Close();
                PowerPoint_App.Quit();
                // VPS Code Ends Here

            }

            catch (Exception ex)
            {
                pptFileName = string.Empty;
            }
            return pptFileName;
        }
Exemple #45
0
		public static void ActivatePowerPoint(Application powerPoint)
		{
			if (powerPoint == null) return;
			var powerPointHandle = new IntPtr(powerPoint.HWND);
			WinAPIHelper.ShowWindow(powerPointHandle, WindowShowStyle.ShowMaximized);
			uint lpdwProcessId;
			WinAPIHelper.AttachThreadInput(WinAPIHelper.GetCurrentThreadId(), WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out lpdwProcessId), true);
			WinAPIHelper.SetForegroundWindow(powerPointHandle);
			WinAPIHelper.AttachThreadInput(WinAPIHelper.GetCurrentThreadId(), WinAPIHelper.GetWindowThreadProcessId(WinAPIHelper.GetForegroundWindow(), out lpdwProcessId), false);
		}
Exemple #46
-1
        public PowerPointControl()
        {
            // OpenFileDialog Instanz erzeugen
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();

            // Dateiendungs-Filter setzen
            dlg.DefaultExt = ".pptx";
            dlg.Filter = "Powerpoint|*.ppt;*.pptx|All files|*.*";

            // OpenFileDialog anzeigen
            Nullable<bool> result = dlg.ShowDialog();

            // PowerPoint Instanz erzeugen
            oPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            // PowerPoint anzeigen
            oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            objPresSet = oPPT.Presentations;

            // Wenn der Benutzer im OpenFileDialog eine Datei ausgewählt + auf OK geklickt hat
            if (result == true)
            {
                // Ausgewählte Datei (Präsentation) öffnen
                objPres = objPresSet.Open(dlg.FileName, MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);

                // Präsentationsansicht öffnen
                objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
                System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation);
                objPres.SlideShowSettings.Run();

                oSlideShowView = objPres.SlideShowWindow.View;
            }
        }
 protected override void Initialize()
 {
     base.Initialize();
     this.Application  = this.GetHostItem <Microsoft.Office.Interop.PowerPoint.Application>(typeof(Microsoft.Office.Interop.PowerPoint.Application), "Application");
     Globals.ThisAddIn = this;
     global::System.Windows.Forms.Application.EnableVisualStyles();
     this.InitializeCachedData();
     this.InitializeControls();
     this.InitializeComponents();
     this.InitializeData();
 }
Exemple #48
-1
        private void OpenPPT()
        {
            //Create an instance of PowerPoint.
            oPPT = new Microsoft.Office.Interop.PowerPoint.Application();
            // Show PowerPoint to the user.
            oPPT.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
            objPresSet = oPPT.Presentations;



                string pptFilePath = "C:\\Users\\bastisusewind\\Desktop\\Test.pptx";
                //open the presentation
                objPres = objPresSet.Open(pptFilePath, MsoTriState.msoFalse,
                MsoTriState.msoTrue, MsoTriState.msoTrue);

                objPres.SlideShowSettings.ShowPresenterView = MsoTriState.msoFalse;
                System.Diagnostics.Debug.WriteLine(objPres.SlideShowSettings.ShowWithAnimation);
                objPres.SlideShowSettings.Run();

                oSlideShowView = objPres.SlideShowWindow.View;

        }