从Word获取RTF [英] Fetch RTF from Word
本文介绍了从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屋!
查看全文