word轉換成HTML 以及IE不相容問題

來源:互聯網
上載者:User

標籤:winform   style   blog   color   io   os   for   檔案   sp   

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()替換成空值,這樣就顯示出來了,業解決掉了不相容的問題

word轉換成HTML 以及IE不相容問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.