zoukankan      html  css  js  c++  java
  • c#操作word类,进行html和word文档的互相转换

    实例引用:http://www.7es.cn/Software_development/171.shtml

    using Microsoft.Office.Core;
    using Word = Microsoft.Office.Interop.Word;

    #region 把Word文档装化为Html文件
            /**//// <summary>
            /// 把Word文档装化为Html文件
            /// </summary>
            /// <param name="strFileName">要转换的Word文档</param>
            public static void WordToHtml( string strFileName )
            {
                string saveFileName = strFileName + DateTime.Now.ToString( "yyyy-MM-dd-HH-mm-ss" ) + ".html";
                WordToHtml( strFileName, saveFileName );
            }
            /**//// <summary>
            /// 把Word文档装化为Html文件
            /// </summary>
            /// <param name="strFileName">要转换的Word文档</param>
            /// <param name="strSaveFileName">要生成的具体的Html页面</param>
            public static void WordToHtml( string strFileName, string strSaveFileName )
            {
                Microsoft.Office.Interop.Word.ApplicationClass WordApp; 
                Microsoft.Office.Interop.Word.Document WordDoc;
                Object oMissing = System.Reflection.Missing.Value;
                WordApp = new Microsoft.Office.Interop.Word.ApplicationClass();
                object fileName = strFileName;
                
                WordDoc = WordApp.Documents.Open( ref fileName,
                   ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
                   ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing );
     
                Type wordType = WordApp.GetType();
                // 打开文件
                Type docsType = WordApp.Documents.GetType();
                // 转换格式,另存为
                Type docType = WordDoc.GetType();
                object saveFileName = strSaveFileName;
                docType.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML } );
     
                #region 其它格式:
                /**//**/
                /**////wdFormatHTML
                ///wdFormatDocument
                ///wdFormatDOSText
                ///wdFormatDOSTextLineBreaks
                ///wdFormatEncodedText
                ///wdFormatRTF
                ///wdFormatTemplate
                ///wdFormatText
                ///wdFormatTextLineBreaks
                ///wdFormatUnicodeText
                //-----------------------------------------------------------------------------------
                //            docType.InvokeMember( "SaveAs", System.Reflection.BindingFlags.InvokeMethod,
                //                null, WordDoc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML} );
                // 退出 Word
                //wordType.InvokeMember( "Quit", System.Reflection.BindingFlags.InvokeMethod,
                //    null, WordApp, null );
                #endregion
                WordDoc.Close( ref oMissing, ref oMissing, ref oMissing );
                WordApp.Quit( ref oMissing, ref oMissing, ref oMissing );
            }
            #endregion

    检索 COM 类工厂中 CLSID 为 {00024500-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。

    问题解决引用:

    http://blog.163.com/wj_1251/blog/static/1502740252012910105027530/

    https://jingyan.baidu.com/article/7e440953d666702fc0e2eff7.html

    配置网站web.config,指定用户访问

    配置服务器上word组件,增加web.config配置用户的操作权限。注:标识使用交互式用户,不然WordApp.Documents.Open时,返回空对象

  • 相关阅读:
    获取父页面标签对象,获取当前标签div高度
    响应回车事件
    解决checkbox的attr(checked)一直为undefined问题
    返回键 隐藏、、收起键盘textView|textField
    ios9 之后,Xcode7不推荐使用UIAlertView,改用UIAlertController+UIAlertAction(按钮)
    判断是否是 首次 进入app,,以及Xcode7之后前导页的设置
    根据 字数 确定 UI控件高度
    对于限制UITextView输入的字符数
    block 反向传值回调
    NSUserDefault的使用
  • 原文地址:https://www.cnblogs.com/0-0snail/p/8479697.html
Copyright © 2011-2022 走看看