请教 如何用C#把.doc文档中的文本转换为字符串,并输出,文本和回车换行等保留,其他如图片等去掉,并别存为.txt文件?请给点资料,谢谢大家.

解决方案 »

  1.   

    用word的组件,以下代码不完整,但主要的都有了.using Word = Microsoft.Office.Interop.Word;//?aê?word′|àí
    Word.Application app = null;
    object missingValue = Type.Missing; 
    object newTextFileName = filename+".txt";
    try {


    app = new Word.Application();
    Word.Document doc = null;
    // C#
    object fileName = filename;
     

     
    object saveTextFormat = Word.WdSaveFormat.wdFormatText;
     
    doc.SaveAs2000(ref newTextFileName,ref saveTextFormat, 
    ref missingValue, ref missingValue,ref missingValue,
    ref missingValue,ref missingValue,ref missingValue,
    ref missingValue,ref missingValue,ref missingValue
    );
    doc.Close(ref missingValue,ref missingValue,ref missingValue);
    }
    ____________________________
    (2005年04月25日 17时25分19秒)
      

  2.   

    以下是转成html的代码,根据不同的选项,可换成不同的输出private string Get_Html(string FileName)
    {
    //FileName 绝对路径
    Word.ApplicationClass word = new Word.ApplicationClass();
    Type wordType = word.GetType();
    Word.Documents docs = word.Documents; // 打开文件
    Type docsType = docs.GetType();
    string newFileNamePath = this.Server.MapPath(FileName);
    Word.Document doc = (Word.Document)docsType.InvokeMember("Open", 
    System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] {newFileNamePath, true, true}); // 转换格式,另存为
    Type docType = doc.GetType();
    object saveFileName = newFileNamePath.Replace(".doc",".htm");
    //下面是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); string newFileName = FileName.Replace(".doc",".htm");
    return(newFileName);
    }
      

  3.   

    hchxxzx(NET?摸到一点门槛)成星星了啊,恭喜恭喜:)
    哪位再给我点资料,或者教教我怎么找资料,谢谢^!^
      

  4.   

    应该不难
    你使用word组件打开这个doc文件
    然后调用另存为接口,保存成txt文件就可以了吧或者你选择doc的所有字符
    然后保存成txt文件当然都要用程序写