zoukankan      html  css  js  c++  java
  • word转换成HTML 以及IE不兼容问题

    public static bool WordToHtml(string wordFileName, string htmlFileName)
            {
                try
                {
                    Object oMissing = System.Reflection.Missing.Value;
                    Microsoft.Office.Interop.Word._Application WordApp = new Microsoft.Office.Interop.Word.Application();
                    WordApp.Visible = false;
                    object filename = wordFileName;
                    _Document 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 = htmlFileName;
                    docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, WordDoc,
                        new object[] { saveFileName, WdSaveFormat.wdFormatHTML });
    
                    //保存
                    WordDoc.Save();
                    WordDoc.Close(ref oMissing, ref oMissing, ref oMissing);
                    WordApp.Quit(ref oMissing, ref oMissing, ref oMissing);
                    return true;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    return false;
                }
            }

    上面的方法是在winform中解决有Word转换成HTML网页的,在转换过程中,会产生一个网页和一个文件夹,如果想将这个网页在前台显示出来,第一步,需要将其这个网页源码中的XXX.files(转换过程中产生的文件夹的名称),转换成正确的路径,但是这样显示出来就会有一个问题,那就是在别的浏览器好使 ,但是在IE浏览器中是什么都不显示的,也就是传说中的不兼容,那么,接下来看我们的第二步.

    第二步:删除源文件中的<![if !vml]> <![endif]><![if !vml]><![endif]>这四个标签,或者用string.Replace()替换成空值,这样就显示出来了,业解决掉了不兼容的问题

    如果您认为这篇文章还不错或者有所收获,您可以点击文章下面的【推荐】按钮精神支持,因为这种支持是我继续写作,分享的最大动力!
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    php排序之冒泡排序
    php排序之快速排序
    php 获取某个月的周次信息
    php 获取目录下文件列表
    计算某个生日是哪个星座的算法
    小物件之radio单选列表
    小物件之select单选下拉列表
    ajax跨域问题
    微信开发第6章 通过accesstoken获取用户粉丝列表
    微信开发第5章 通过accesstoken获取用户基本信息并修改用户备注
  • 原文地址:https://www.cnblogs.com/gskstudy/p/3995429.html
Copyright © 2011-2022 走看看