예제 #1
0
        private void pwerPntBtn_MouseEnter(object sender, EventArgs e)
        {
            this.mpModeBtn.BackColor      = Color.Black;
            this.pwerPntBtn.BackColor     = Color.Coral;
            this.browserModeBtn.BackColor = Color.Black;
            Auxiliar.modoDeOperacao       = Auxiliar.ModoDeOperacao.POWERPOINT;
            this.colorPal.Visible         = false;
            MessageForm frm = new MessageForm("Presentation Mode");

            Principal.ppt = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            frm.Show();
        }
예제 #2
0
        public override bool PPT2HTML(string sourcePath, string targetPath, string targetRelativeDirectory)
        {
            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.Application  pptApp       = null;
            Microsoft.Office.Interop.PowerPoint.Presentation presentation = null;
            try
            {
                if (!sourcePath.EndsWith(".ppt") && !sourcePath.EndsWith(".pptx"))
                {
                    return(false);
                }

                if (File.Exists(targetPath))
                {
                    File.Delete(targetPath);
                }
                object target = targetPath;
                pptApp = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                Microsoft.Office.Interop.PowerPoint.Presentations presentations = pptApp.Presentations;

                presentation = presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                presentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
            }
            catch (Exception e)
            {
                Log.LogInfo("ppt转换html:", e);
                return(false);
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    presentation = null;
                }
                if (pptApp != null)
                {
                    pptApp.Quit();
                    pptApp = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            pptHelper(targetPath, targetRelativeDirectory);

            return(true);
        }
예제 #3
0
        ///<summary>
        /// 把PowerPoint文件转换成PDF格式文件
        ///</summary>
        ///<param name="sourcePath">源文件路径(物理路径)</param>
        ///<param name="targetPath">目标文件路径(物理路径)</param>
        ///<returns>true=转换成功</returns>
        public static bool PPTConvertToPDF(string sourcePath, string targetPath)
        {
            bool result;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation     persentation = null;
            try
            {
                application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                //打开
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                if (persentation != null)
                {
                    //写入
                    persentation.SaveAs(targetPath, targetFileType, MsoTriState.msoTrue);
                }
                result = true;
            }
            catch
            {
                result = false;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
예제 #4
0
        /// <summary> 把PowerPoint文件转换成PDF格式文件</summary>   
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>   
        public static bool PowerPointToBMP(string sourcePath, string targetPath)
        {
            bool result = false;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsBMP;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null; Microsoft.Office.Interop.PowerPoint.Presentation persentation = null;
            try
            {
                application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                //application.Visible = MsoTriState.msoFalse;
                persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                persentation.SaveAs(targetPath, targetFileType, MsoTriState.msoTrue);
                result = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                result = false;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            return(result);
        }
예제 #5
0
        //dll import end

        static void Main(string[] args)
        {
            StringBuilder name   = new StringBuilder(128);
            UInt32        len    = 128;
            int           result = GetComputerName(name, ref len);

            Console.WriteLine(name);

            emp e = new emp();

            e.name = "bob";
            emp e2 = new emp();

            e2 = (emp)e.Clone();
            e.print_t4();
            //disposing of class memory
            //1. Make it null
            e = null; //does not remove the memory immediately
            //2.  Put in brackets
            {
                emp f = new emp(); //does not remove the memory immediately
            }
            //3. Do 1 or 2 and then issue Collect command
            System.GC.Collect();   //memory is gone
            //4. Use IDisposable interface to remove memory
            using (emp g = new emp())
            {
                //do coding here
            }//memory is removed here

            //call a DLL from .NET
            string person = Microsoft.VisualBasic.Interaction.InputBox("Enter your name");

            Console.WriteLine(person);
            //call a COM program
            Microsoft.Office.Interop.PowerPoint.ApplicationClass p = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
            //p.Help();


            Console.ReadLine();
        }
        private void PPTToPDF(string path, string extend)
        {
            string filePath = HttpContext.Current.Server.MapPath(path);
            string outPath  = HttpContext.Current.Server.MapPath(path).Replace(extend, ".pdf");

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation     presentation = null;
            try
            {
                application  = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                presentation = application.Presentations.Open(filePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                presentation.SaveAs(outPath, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF, MsoTriState.msoTrue);

                Utils.StringToTxt("UploadHandler.ashx=>PPTToPDF:成功");
            }
            catch (Exception ex)
            {
                Utils.StringToTxt("UploadHandler.ashx=>PPTToPDF:失败。" + ex.Message);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (presentation != null)
                {
                    presentation.Close();
                    presentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
예제 #7
0
        /// <summary>
        /// 把PowerPoint文件转换成PDF格式文件
        /// </summary>
        /// <param name="sourcePath">源文件路径</param>
        /// <param name="targetPath">目标文件路径</param>
        /// <returns>true=转换成功</returns>
        public static bool PowerPointToPDF(string sourcePath, string targetPath)
        {
            targetPath = Regex.Replace(targetPath, " ", "", RegexOptions.IgnoreCase);//去除字符串中间的空格
            bool result;

            Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType targetFileType = Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPDF;
            object missing = Type.Missing;

            Microsoft.Office.Interop.PowerPoint.ApplicationClass application  = null;
            Microsoft.Office.Interop.PowerPoint.Presentation     persentation = null;
            try
            {
                bool TimeOver             = false; //转换时间到了
                System.Timers.Timer timer = new System.Timers.Timer(30000);
                timer.AutoReset = false;           //只循环一次
                timer.Elapsed  += delegate(object sender, System.Timers.ElapsedEventArgs e)
                {
                    TimeOver = true;
                };
                timer.Start();
                Thread th = new Thread(new ThreadStart(delegate()
                {
                    try
                    {
                        application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();
                        //application.Visible = MsoTriState.msoFalse;
                        persentation = application.Presentations.Open(sourcePath, MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);
                        persentation.SaveAs(targetPath, targetFileType, Microsoft.Office.Core.MsoTriState.msoTrue);
                    }
                    catch
                    {
                    }
                }));
                th.IsBackground = true;//后台线程
                th.Start();
                //如果转换没有成功就一直循环
                while (th.ThreadState != System.Threading.ThreadState.Stopped)
                {
                    //如果一直没有转换成功,但是最大的转换时间到了也直接跳出While循环
                    if (TimeOver)
                    {
                        break;
                    }
                }
                if (th.ThreadState != System.Threading.ThreadState.Stopped)
                {
                    th.Abort();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                result = false;
            }
            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            //判断文件是否转换成功
            if (File.Exists(targetPath))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }