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

    如果您认为这篇文章还不错或者有所收获,您可以点击文章下面的【推荐】按钮精神支持,因为这种支持是我继续写作,分享的最大动力!
    声明:原创博客请在转载时保留原文链接或者在文章开头加上本人博客地址,如发现错误,欢迎批评指正。凡是转载于本人的文章,不能设置打赏功能,如有特殊需求请与本人联系!
  • 相关阅读:
    C# 16进制字节转Int(涉及:Base64转byte数组)
    c# CRC-16 / MODBUS 校验计算方法 及 异或校验算法
    SqlSugar 用法大全
    SQL Server-聚焦NOLOCK、UPDLOCK、HOLDLOCK、READPAST你弄懂多少?
    使用 tabindex 配合 focus-within 巧妙实现父选择器
    DataX 3.0 源码解析一
    Golang必备技巧:接口型函数
    PID控制
    dockerfile,拷贝文件夹到镜像中(不是拷贝文件夹中的内容到镜像)
    什么是PKI?主要作用是什么?
  • 原文地址:https://www.cnblogs.com/gskstudy/p/3995429.html
Copyright © 2011-2022 走看看