当前位置: 首页>>代码示例>>C#>>正文


C# ApplicationClass.GetType方法代码示例

本文整理汇总了C#中ApplicationClass.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationClass.GetType方法的具体用法?C# ApplicationClass.GetType怎么用?C# ApplicationClass.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ApplicationClass的用法示例。


在下文中一共展示了ApplicationClass.GetType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Word2Pdf

 public static void Word2Pdf(string path, string savepath)
 {
     var word = new ApplicationClass();
     var wordType = word.GetType();
     var docs = word.Documents;
     var docsType = docs.GetType();
     var doc = (Document) docsType.InvokeMember(
         "Open",
         BindingFlags.InvokeMethod,
         null,
         docs,
         new[] {(object)path, true, true});
     var docType = doc.GetType();
     docType.InvokeMember(
         "SaveAs",
         BindingFlags.InvokeMethod,
         null,
         doc,
         new[] {(object) savepath, WdSaveFormat.wdFormatPDF});
     docType.InvokeMember(
         "Close",
         BindingFlags.InvokeMethod,
         null,
         doc,
         new object[] {WdSaveOptions.wdDoNotSaveChanges});
     wordType.InvokeMember(
         "Quit",
         BindingFlags.InvokeMethod,
         null,
         word,
         null);
 }
开发者ID:jinghang,项目名称:DevHelper,代码行数:32,代码来源:Program.cs

示例2: WordToHtml

        /// <summary> 
        /// word 转成html 
        /// </summary> 
        /// <param name="path">实际目录</param> 
        /// <param name="fileName">文件名</param>
        /// <param name="path">文件相对路径</param> 
        public static string WordToHtml(string path, string fileName, string fileRelaUrl)
        {
            string wordFileUrl = path + fileName;  //文件实际路径
            string htmlFileUrl = fileEndWithHtml(wordFileUrl.ToString());  //将要生成的html文件实际路径

            //if (!File.Exists(htmlFileUrl))
            //{
            try
            {

                SPSecurity.RunWithElevatedPrivileges(delegate()
            {
              //在此处放置用户代码以初始化页面
              ApplicationClass word = new ApplicationClass();
              Type wordType = word.GetType();
              Documents docs = word.Documents;

              //打开文件
              Type docsType = docs.GetType();
              Document doc = (Document)docsType.InvokeMember("Open",
              System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileUrl, true, true });

              //转换格式,另存为
              Type docType = doc.GetType();

              docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
               null, doc, new object[] { htmlFileUrl, WdSaveFormat.wdFormatFilteredHTML });

              docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,
               null, doc, null);

              //退出 Word
              wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
               null, word, null);

              //Thread.Sleep(3000); //为了使退出完全,这里阻塞3秒
            });
            }

            catch (Exception ex)
            {
                throw ex;
            }

            //}

            return fileEndWithHtml(fileRelaUrl);    //html文件相对路径
        }
开发者ID:porter1130,项目名称:C-A,代码行数:54,代码来源:Util.cs

示例3: WordToHtml

        /// <summary>
        /// word转成html
        /// </summary>
        /// <param name="wordFileName"></param>
        private string WordToHtml(object wordFileName)
        {
            //在此处放置用户代码以初始化页面
            ApplicationClass word = new ApplicationClass();
            Type wordType = word.GetType();
            Documents docs = word.Documents;

            //打开文件
            Type docsType = docs.GetType();
            Document doc = (Document)docsType.InvokeMember("Open",
            System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { wordFileName, true, true });

            //转换格式,另存为
            Type docType = doc.GetType();

            string wordSaveFileName = wordFileName.ToString();
            string strSaveFileName = wordSaveFileName.Substring(0, wordSaveFileName.Length - 3) + "html";
            object saveFileName = (object)strSaveFileName;
            //下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成如下,不明之处欢迎到Programbbs.com讨论
            /*
            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
             null, doc, new object[]{saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML});
            */
            ///其它格式:
            ///wdFormatHTML
            ///wdFormatDocument
            ///wdFormatDOSText
            ///wdFormatDOSTextLineBreaks
            ///wdFormatEncodedText
            ///wdFormatRTF
            ///wdFormatTemplate
            ///wdFormatText
            ///wdFormatTextLineBreaks
            ///wdFormatUnicodeText
            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
             null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatHTML });

            docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod,
             null, doc, null);

            //退出 Word
            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
             null, word, null);

            return saveFileName.ToString();
        }
开发者ID:kosmos-zhang,项目名称:erp-aspnet,代码行数:50,代码来源:ImportWord.aspx.cs

示例4: WordSavaAs

        /// <summary>
        /// word保存为html
        /// </summary>
        /// <param name="oriWordPath"></param>
        /// <param name="destFilePath"></param>
        /// <returns></returns>
        public static bool WordSavaAs(string oriWordPath,string destFilePath)
        {
            try
            {
                #region 文件格式转换
                //请引用Microsoft.Office.Interop.Word
                ApplicationClass word = new ApplicationClass();
                Type wordType = word.GetType();
                Documents docs = word.Documents;

                // 打开文件
                Type docsType = docs.GetType();
                object fileName = oriWordPath; //"f:\\cc.doc";
                Document doc = (Document)docsType.InvokeMember("Open", BindingFlags.InvokeMethod, null, (object)docs, new Object[] { fileName, true, true });

                //判断与文件转换相关的文件是否存在,存在则删除。(这里,最好还判断一下存放文件的目录是否存在,不存在则创建)
                if (File.Exists(destFilePath)) { File.Delete(destFilePath); }
                //每一个html文件,有一个对应的存放html相关元素的文件夹(html文件名.files)
                if (Directory.Exists(destFilePath.Replace(".html", ".files")))
                {
                    Directory.Delete(destFilePath.Replace(".html", ".files"), true);
                };

                //转换格式,调用word的“另存为”方法
                Type docType = doc.GetType();
                object saveFileName = destFilePath; //"f:\\aaa.html";
                docType.InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, WdSaveFormat.wdFormatHTML });

                // 退出 Word
                wordType.InvokeMember("Quit", BindingFlags.InvokeMethod, null, word, null);

                #endregion
                return true;
            }
            catch { return false; }            
        }
开发者ID:LeehanLee,项目名称:L.W,代码行数:42,代码来源:DocxUtil.cs

示例5: Convert

        public int Convert(string sourcePath, string targetPath)
        {
            if (!File.Exists(sourcePath))
            {
                return ErrorMessages.FileNotExist;
            }

            ApplicationClass wordApplication = new ApplicationClass();
            Document wordDocument = null;
            object paramMissing = Type.Missing;
            Type wordType = wordApplication.GetType();

            try
            {
                object paramSourceDocPath = sourcePath;
                string paramExportFilePath = targetPath;

                //wordDocument = wordApplication.Documents.Open(
                //    ref paramSourceDocPath, ref paramMissing, ref paramMissing,
                //    ref paramMissing, ref paramMissing, ref paramMissing,
                //    ref paramMissing, ref paramMissing, ref paramMissing,
                //    ref paramMissing, ref paramMissing, ref paramMissing,
                //    ref paramMissing, ref paramMissing, ref paramMissing,
                //    ref paramMissing);

                Documents docs = wordApplication.Documents;
                Type docsType = docs.GetType();
                wordDocument = (Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { sourcePath, true, true });

                if (wordDocument != null)
                {
                    WdExportFormat paramExportFormat = WdExportFormat.wdExportFormatPDF;
                    bool paramOpenAfterExport = false;
                    WdExportOptimizeFor paramExportOptimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
                    WdExportRange paramExportRange = WdExportRange.wdExportAllDocument;
                    int paramStartPage = 0;
                    int paramEndPage = 0;
                    WdExportItem paramExportItem = WdExportItem.wdExportDocumentContent;
                    bool paramIncludeDocProps = true;
                    bool paramKeepIRM = true;
                    WdExportCreateBookmarks paramCreateBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks;
                    bool paramDocStructureTags = true;
                    bool paramBitmapMissingFonts = true;
                    bool paramUseISO19005_1 = false;

                    wordDocument.ExportAsFixedFormat(paramExportFilePath,
                                                    paramExportFormat, paramOpenAfterExport,
                                                    paramExportOptimizeFor, paramExportRange, paramStartPage,
                                                    paramEndPage, paramExportItem, paramIncludeDocProps,
                                                    paramKeepIRM, paramCreateBookmarks, paramDocStructureTags,
                                                    paramBitmapMissingFonts, paramUseISO19005_1,
                                                    ref paramMissing);
                }
                return ErrorMessages.ConvertSuccess;
            }
            catch (COMException ex)
            {
                _logger.Error(ex.StackTrace);
                _logger.Error(ex.Message);
                return ErrorMessages.OfficeToPdfUninstall;
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return ErrorMessages.ConvertFailed;
            }
            finally
            {
                if (wordDocument != null)
                {
                    wordDocument.Close(ref paramMissing, ref paramMissing, ref paramMissing);
                }
                wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, wordApplication, null);
                GC.Collect();
                GC.WaitForPendingFinalizers();
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
开发者ID:ideayapai,项目名称:docviewer,代码行数:79,代码来源:WordToPDFConverter.cs


注:本文中的ApplicationClass.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。