使用范围

如果您使用过Microsoft WordAutomation,您可能知道检查和修改文档内容的主要工具之一是Range对象。 Range就像文档内容和格式的"窗口"。

Aspose.Words也有Range类,它的设计与Microsoft Word中的Range类似。 虽然Range不能复盖文档的任意部分并且没有StartEnd,但您可以访问包括Document本身在内的任何文档节点所复盖的范围。 换句话说,每个节点都有自己的范围。 Range对象允许您访问和修改范围内的文本、书签和表单字段。

检索纯文本

使用Text属性检索范围的纯文本、无格式文本。

下面的代码示例演示如何获取范围的纯文本、无格式文本:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directory.
System::String inputDataDir = GetInputDataDir_WorkingWithRanges();
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc");
System::String text = doc->get_Range()->get_Text();

删除文本

Range允许通过调用Delete删除范围的所有字符。

下面的代码示例演示如何删除范围的所有字符:

For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C
// The path to the documents directory.
System::String inputDataDir = GetInputDataDir_WorkingWithRanges();
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc");
doc->get_Sections()->idx_get(0)->get_Range()->Delete();