简体   繁体   English

从范围中提取富文本格式的文本

[英]extract text in rich text format from range

How can I extract the RTF content from the Range (Microsoft.Interop.Word.Range class) of word document?如何从 Word 文档的 Range(Microsoft.Interop.Word.Range 类)中提取 RTF 内容? Range has property named "Text" but it returns the plain text and not the RTF Text. Range 具有名为“Text”的属性,但它返回纯文本而不是 RTF 文本。 So how I can get the RTF text from Range?那么如何从 Range 中获取 RTF 文本呢?

Word's native format is not RTF - a conversion is necessary to get Word Open XML (or binary) content as RTF. Word 的本机格式不是 RTF - 需要进行转换才能将 Word Open XML(或二进制)内容作为 RTF。 That means there are three possibilities:这意味着存在三种可能性:

  1. Save the document to the RTF format (or copy the Range to a new document and save it to RTF format), then extract the RTF from the file.将文档保存为 RTF 格式(或将 Range 复制到新文档并保存为 RTF 格式),然后从文件中提取 RTF。
  2. Copy the Range to the Clipboard .将范围复制到剪贴板 Word puts its content in multiple formats on the Clipbord, including RTF. Word 将其内容以多种格式放在剪贴板上,包括 RTF。 You should be able to extract the Clipboard content, therefore, as RTF.因此,您应该能够将剪贴板内容提取为 RTF。
  3. Find (or create) a conversion tool that can convert Word Open XML to RTF.查找(或创建)可以将 Word Open XML 转换为 RTF 的转换工具。 Extract the Word Open XML using Range.WordOpenXML to a string, then run that through the conversion tool.使用Range.WordOpenXML将 Word Open XML 提取为字符串,然后通过转换工具运行该字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM