Replace text inWord Document

We’re happy to release 19.7 version of Aspose.Words Cloud. In this release, we’ve introduced working with Range feature, PDF to Word conversion enhancement, all new Aspose.Words Cloud SDK for .NET, along with many other fixes. Read on to see what’s new.

Range API

If you’re familiar with the Microsoft Word Automation, you would know that the most commonly used object in it is Range object. The Range Object enables a user to specify a contiguous area in a document and then allow to modify it, such as insert text or apply formatting.

With this release, we’ve introduced the Range API in Aspose.Words Cloud. The concept of the Range is similar to Range Object in MS Word API. It is signified as a pair of positions (START, END), where a coordinate of START always less than a coordinate of END. It may span across multiple sections, paragraphs, etc., in other words, across different nodes of the DOM tree. Thus, a user can ignore the underlying model of the document. Such approach is going to make the usage of API much more friendly.

Currently, our Range feature has just very basic functionality, but we have a future plan to make it as convenient as the Range object of Microsoft Word Automation.

Let’s give you some overview of Range API, for details please visit documentation.

How to specify a Range?

Aspose.Words Cloud provides three options to specify a range in a document:

Based on nodes IDs

/range/{startId}/{endId}

{startId} - id of the node from which the range starts (included). Required.

{endId} - id of the node at which the range ends (excluded). Optional. If missed, the end of the range corresponds to the end of the node with id = startId, i.e. the range is limited by the bounds of “startId node”.

Based on pseudo names of nodes

/range/{startPseudoName}/{endPseudoName}

{startPseudoName} - a pseudo name of the node from which the range starts (included). Required.

{endPseudoName} - a pseudo name of the node at which the range ends (excluded). Optional. If missed, the end of the range corresponds to the end of the node with pseudoname = startPseudoName, i.e. the range is limited by the bounds of “startPseudoName node”.

Current available pseudonames are TableN for tables and ImageN for images.

Based on positions inside nodes

/range/{startIdentifier}:{startSelector}/{endIdentifier}:{endSelector}

{startIdentifier} - an identifier (id or a pseudo name) of the node from which the range starts (included). Required.

{endIdentifier} - an identifier (id or a pseudo name) of the node at which the range ends (excluded). Optional. If missed, the end of the range corresponds to the end of the node with identifier = startIdentifier, i.e. the range is limited by the bounds of “startIdentifier node”.

{startSelector} - a selector which specifies the certain position inside the start node (included). Optional. If missed, the start of the range corresponds to the beginning of the start node.

{endSelector} - a selector which specifies the certain position inside the end node (excluded). Optional. If missed, the end of the range corresponds to the element before the beginning of the end node.

A certain position inside a node can be specified with a selector which is separated from a node identifier with a colon. Selectors cannot be used without node identifier. Currently, Range API supports the end selector.

The end selector specifies the end of the node (“end” here is supposed to be a virtual node after the last child node, i.e. it means that the whole content of the node should be included).

Operations Supported with a Range

Currently we’re supporting following operations with a Range:

Get the text from the range

Remove the text from the range

Replace the content in the range

Save the selected range as a new document

For a quick demonstration, here we show you how easily you can replace the content in the range with simple HTTP request using cURL command. However, you can use Aspose.Words Cloud SDK of your favorite language in your application without worrying about underlying API calls.

First, call the Paragraph API to get a list of paragraphs that are contained in the document.

We need to replace content of first paragraph of the document. You see that second paragraph correspond to NodeId id0.0 in the response, so we’ll call Range API to replace the content like:

You can visit the release notes for a complete list of improvement and fixes.

Experience Aspose.Words Cloud

If you’ve not already tried our REST API, we encourage you to head over to Aspose.Words Cloud with a free trial today. All you need is to sign up with the aspose.cloud. Once you’ve signed up, you may go through the following useful resources of Aspose.Words Cloud.

Looking for Your Feedback

Your feedback is very important for us. If you’ve any suggestions or if you need any particular features which you expect our REST API to have, please feel free to drop us a comment below or at support forum.

Suggested Post:

Convert Word Document to Binary TIFF Image