office.js range.load(‘text’) doesn’t return all text when there are two many hyperlinks in range

It is not recommended that you get the entire text from document.body object. There is a limit so you may not be able to retrieve the whole text if the amount of body text goes over the limit. Instead, you could achieve the same goal by looping through the paragraphs collection.

  await (context) => {
    const body = context.document.body;
    var paragraph = body.paragraphs.getFirstOrNullObject();
    await context.sync();
    while (!paragraph.isNullObject) {
      paragraph = paragraph.getNextOrNullObject();
      await context.sync();

Here is a link to the gist you could import via ScriptLab.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top