Search code examples
ms-wordoffice-jsword-addins

Insert a line break with inserted text in a Word document


Building a word add-in using javascript (office.js) to insert text. So far unformatted text with .insertText. If I would like to insert the below, which function should be used?

  • formatted text (for instance size, font, style)
  • Line break
  • Bullet point

Code:

results.items[i].insertText("Any text going here.", "replace");

How would I for instance insert a line break in the "Any text going here"?


Solution

  • Using JavaScript, add a "line-break" (I'm assuming you mean the same as pressing ENTER in the UI - this is technically a new paragraph) using the string "\n". So, for example:

    results.items[i].insertText("Any text going here.\n", "replace");