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()替换成空值,这样就显示出来了,业解决掉了不兼容的问题

    如果您认为这篇文章还不错或者有所收获,您可以点击文章下面的【推荐】按钮精神支持,因为这种支持是我继续写作,分享的最大动力!
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    oracle解决连接池不足
    ORA-12537:TNS连接已关闭
    oracle 11g 大量废连接占满数据库连接问题处理
    oracle: 浅谈sqlnet.ora文件的作用,及SQLNET.AUTHENTICATION_SERVICES设置
    查询oracle数据库的数据库名、实例名、ORACLE_SID
    工程:有价值的事物的创建过程,及依赖的资源与知识
    工程学
    并发的本质是任务空间与执行空间
    异步的本质是不确定性
    聊一聊 redux 异步流之 redux-saga
  • 原文地址:https://www.cnblogs.com/gskstudy/p/3995429.html
Copyright © 2011-2022 走看看