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 Word.run(async (context) => {
const body = context.document.body;
var paragraph = body.paragraphs.getFirstOrNullObject();
paragraph.load("text");
await context.sync();
while (!paragraph.isNullObject) {
console.log(paragraph.text);
paragraph = paragraph.getNextOrNullObject();
paragraph.load("text");
await context.sync();
}
});
Here is a link to the gist you could import via ScriptLab.
CLICK HERE to find out more related problems solutions.