如何读取使用.NET 4.0 .rtf文件文件、NET、rtf

2023-09-07 02:39:58 作者:初泽

我已经看到了使用Word 9.0对象库的样本。但我有Office 2010测试版和.NET 4.0在VS2010。如何去与新的Word的dll任何提示?

I have seen samples using Word 9.0 object library. But I have Office 2010 Beta and .NET 4.0 in VS2010. Any tips on how to go with the new Word Dlls?

所以,我只是想获得RTF格式的功能,以文本.NET3.5或更高版本。

So I just wanted to get the functionality of RTF to TEXT with .NET3.5 or later.

推荐答案

我用WPF更好的解决方案,使用的TextRange。

I got a better solution with WPF , using TextRange.

FlowDocument document = new FlowDocument();

//Read the file stream to a Byte array 'data'
TextRange txtRange = null;

using (MemoryStream stream = new MemoryStream(data))
{
    // create a TextRange around the entire document
    txtRange = new TextRange(document.ContentStart, document.ContentEnd);
    txtRange.Load(stream, DataFormats.Rtf);
}

现在你可以看到里面documentTextRange.Text所提取的文本

Now you can see the extracted text inside documentTextRange.Text