使用范围
Contents
[
Hide
]
在 Aspose.Words 中,Range 是文档树状模型的"平面窗口"。
如果您使用过 Microsoft Word Automation,您可能知道检查和修改文档内容的主要工具之一是 Range 对象。 Range 就像一个了解文档内容和格式的"窗口"。 Aspose.Words 还具有 Range 类,其设计的外观和行为与 Microsoft Word 中的 Range 类似。尽管 Range 无法覆盖文档的任意部分,并且没有 Start 和 End,但您可以访问任何文档节点(包括 Document 本身)覆盖的范围。换句话说,每个节点都有自己的范围。 Range 对象允许您访问和修改范围内的文本、书签和表单字段。
检索纯文本
使用 text 属性检索范围内的纯文本、无格式文本。
以下代码示例演示如何获取某个范围的纯文本、无格式文本:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET | |
doc = aw.Document(docs_base.my_dir + "Document.docx") | |
text = doc.range.text |
您可以从 Aspose.Words GitHub 下载本示例的示例文件。
删除文本
Range允许通过调用delete删除该范围内的所有字符。
以下代码示例显示如何删除某个范围内的所有字符:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET | |
doc = aw.Document(docs_base.my_dir + "Document.docx") | |
doc.sections[0].range.delete() |
您可以从 Aspose.Words GitHub 下载本示例的示例文件。