ppt转成jpg的方法

2015-03-02 12:23:12  访问(1953) 赞(0) 踩(0)


        /// <summary>
        /// <para>ppt转成jpg的方法</para>
        /// <para>添加两个引用,Microsoft.Office.Interop.PowerPoint;并在引用中把该引用的“嵌入互操作类型”属性改成false,还有office引用,就可以了!这是在windowform写的,web也是一样</para>
        /// <para>添加后还是编译错误,我后面把office全装了,而不是选择安装就可以了</para>
        /// <para>office里面有开发组件用安装,才能编译通过</para>
        /// </summary>
        /// <param name="pptFileName"></param>
        /// <returns></returns>
        public string ToJpg(string pptFileName)
        {
            string theResult = "";

            object missing = Type.Missing;
            Microsoft.Office.Interop.PowerPoint.ApplicationClass application = null;
            Presentation persentation = null;

            try
            {
                // 要转换的文件物理路径
                string savePath = System.IO.Path.ChangeExtension
                    (
                        pptFileName, 
                        ".jpg"
                    );

                application = new Microsoft.Office.Interop.PowerPoint.ApplicationClass();

                persentation = application.Presentations.Open
                    (
                        pptFileName,
                        Microsoft.Office.Core.MsoTriState.msoTrue,
                        Microsoft.Office.Core.MsoTriState.msoFalse,
                        Microsoft.Office.Core.MsoTriState.msoFalse
                    );
                persentation.SaveAs(savePath, PpSaveAsFileType.ppSaveAsJPG, Microsoft.Office.Core.MsoTriState.msoTrue);
                 

            }
            catch (Exception err)
            {
                theResult = "转换异常:" + err.Message;
            }

            finally
            {
                if (persentation != null)
                {
                    persentation.Close();
                    persentation = null;
                }
                if (application != null)
                {
                    application.Quit();
                    application = null;
                }
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            return theResult;
        }


上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)