An Office service that supports add-ins to interact with objects in Office client applications.
Hello @Rajat Bharadwaj
With the current production Word JavaScript APIs, there isn’t a built-in range/content-control diff API that compares two strings and automatically generates granular tracked changes for only the modified characters. contentControl.insertText(..., "Replace") replaces the complete content of that control, so with Track Changes enabled, Word can mark the whole old value as deleted and the whole replacement as inserted.
Document.compare() and compareFromBase64() are document-level, desktop-only APIs. They compare the active document against another document and can't be scoped to a particular Range or content control. compareFromBase64() also doesn't support compareTargetSelected.
So for production code, if you need changes such as only 70 → 30 to appear as tracked revisions, the practical approach is to calculate the diff yourself and apply the smallest possible edits to corresponding ranges. The newer Range.start/end properties are available in WordApiDesktop 1.4, but that makes this approach dependent on the desktop version.
For Word on the web or older clients, you would need to fall back to APIs supported by those requirement sets, typically locating text/ranges with the existing range/search APIs and performing targeted insertText operations rather than relying on writable character offsets.
For complex content containing paragraph marks, tables, fields, nested controls, or mixed formatting, do not treat the document as one flat string. Diff and modify within stable structural boundaries, and avoid deleting/recreating the outer content control. Targeted edits inside it preserve the control itself, including its tag; replacing the whole control content risks losing more formatting/revision fidelity than necessary.
References:
So in short: no production API currently performs granular tracked-change diffing for a range automatically; targeted edits based on your own diff are the supported pattern.
Help make this community better for everyone: if this answer resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution.