C#中word文档转html

                        var path = Request.Url.Host + ":" + Request.Url.Port + list[i].AnnexPath;
                        //html保存路径
                        string savePath = Server.MapPath("~/Uploads/RemoteDatum/");
                        if (!Directory.Exists(savePath))
                        {
                            Directory.CreateDirectory(savePath);
                        }
                        //将word转成html
                        if (!System.IO.File.Exists(savePath + list[i].AnnexId + ".html"))
                        {
                            Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
                            Type wordType = word.GetType();
                            Documents docs = word.Documents;
                            Type docsType = docs.GetType();
                            Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { (object)path, true, true });
                            Type docType = doc.GetType();
                            string strSaveFileName = savePath + list[i].AnnexId + ".html";
                            object saveFileName = (object)strSaveFileName;
                            docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod, null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });
                            docType.InvokeMember("Close", System.Reflection.BindingFlags.InvokeMethod, null, doc, null);
                            wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
                        }
                        var htmlPath = "/Uploads/RemoteDatum/" + list[i].AnnexId + ".html";

 

posted @ 2017-09-18 09:50  雷雨天的雷胖子  阅读(683)  评论(0编辑  收藏  举报