asp.net将word转成HTML

 // 在此处放置用户代码以初始化页面
        Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
        Type wordType = word.GetType();
        Microsoft.Office.Interop.Word.Documents docs = word.Documents; 
        // 打开文件
        Type docsType = docs.GetType();
        object fileName = "c:\\test\\a.docx";
        Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document)docsType.InvokeMember("Open",
            System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });

        // 转换格式,另存为
        Type docType = doc.GetType();
        object saveFileName = "c:\\test\\test.html";
        ///其它格式:
        ///wdFormatHTML
        ///wdFormatDocument
        ///wdFormatDOSText
        ///wdFormatDOSTextLineBreaks
        ///wdFormatEncodedText
        ///wdFormatRTF
        ///wdFormatTemplate
        ///wdFormatText
        ///wdFormatTextLineBreaks
        ///wdFormatUnicodeText
        docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
            null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatHTML });

        // 退出 Word
        wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
            null, word, null);

 

posted @ 2012-12-30 23:01  csdnbbs  阅读(189)  评论(1编辑  收藏  举报