有人通过下面这种方法将word转为html,private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
    Word.ApplicationClass word = new Word.ApplicationClass();
    Type wordType = word.GetType();
    Word.Documents docs = word.Documents;    // 打开文件
    Type docsType = docs.GetType();
    object fileName = "d:\\tmp\\aaa.doc";
    Word.Document doc = (Word.Document)docsType.InvokeMember("Open", 
    System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
          
    // 转换格式,另存为
    Type docType = doc.GetType();
    object saveFileName = "d:\\tmp\\aaa.html";
    //下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
    //docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
     null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
    ///其它格式:
    ///wdFormatHTML
    ///wdFormatDocument
    ///wdFormatDOSText
    ///wdFormatDOSTextLineBreaks
    ///wdFormatEncodedText
    ///wdFormatRTF
    ///wdFormatTemplate
    ///wdFormatText
    ///wdFormatTextLineBreaks
    ///wdFormatUnicodeText
    docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
     null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML});    // 退出 Word
    wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
     null, word, null);
}现在我想取出已转换为html文件的文本内容,要如何实现?请大家帮忙,谢谢

解决方案 »

  1.   

    把所有的html标记用正则表达式替换掉。
      

  2.   

    不好意思,我写错了,我的意思是取出这个html文件中的所有内容,不单单是其中的文本,还包括它的标记什么的啊
      

  3.   

    都已经转换成html,你还要取什么?
      

  4.   

    是成功转换保存成了html文件啊,那我要取出这个html文件的代码啊,要怎么取了?
      

  5.   

    这个word文件已经被你转化之后保存成了一个html文件。你现在要把这个html文件当作文本读到内存里去?
      

  6.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
        Word.ApplicationClass word = new Word.ApplicationClass();
        Type wordType = word.GetType();
        Word.Documents docs = word.Documents;    // 打开文件
        Type docsType = docs.GetType();
        object fileName = "d:\\tmp\\aaa.doc";
        Word.Document doc = (Word.Document)docsType.InvokeMember("Open", 
        System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {fileName, true, true});
              
        // 转换格式,另存为
        Type docType = doc.GetType();
        object saveFileName = "d:\\tmp\\aaa.html"; //<-这里已经有了保存路径
        docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
         null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatHTML});    // 退出 Word
        wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod,
         null, word, null);
        
        //读取已经保存的文件
        Sysetem.IO.StreamReader sr = new StreamReader(saveFileName.ToString(),
        Encoding.Default);
        string strHtml = sr.ReadToEnd();//<-strHtml中就是Html的文本了。
        sr.Close();}