从 Word 中获取 RTF [英] Fetch RTF from Word

查看:22
本文介绍了从 Word 中获取 RTF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Word 文档,想将内容导出为 RTF(或 html)格式.

I have a Word document and would like to export the content including the format as RTF (or html).

        Word.Application wordApp = new Word.Application();
        Word.Document currentDoc = wordApp.Documents.Open("file.docx");
        currentDoc.SaveAs("file.rtf", Word.WdSaveFormat.wdFormatRTF);
        currentDoc = wordApp.Documents.Open("file.rtf");
        Word.Range range = currentDoc.Range();
        String RTFText = range.Text;

我已经尝试了上面的代码,但我似乎只得到了文本,没有 hte 格式.

I've tried the code above, but i seem to get just the Text, without hte format.

有什么想法吗?

推荐答案

如果你想阅读 rtf 代码,请尝试使用:

If you want to read the rtf code just try to use:

Word.Application wordApp = new Word.Application();
Word.Document currentDoc = wordApp.Documents.Open("file.docx");
currentDoc.SaveAs("file.rtf", Word.WdSaveFormat.wdFormatRTF);

然后像普通文本文件一样打开它:

And then open it like a normal text file:

string rtf = File.ReadAllText("file.rtf");

使用您的方法不起作用,因为您正在访问 Text 属性,因此 Word 只为您提供纯文本.

Using your method doesn't work because you're accessing Text property, so Word gives you only plain text.

这篇关于从 Word 中获取 RTF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆