Range.insertHtml not setting styles in Office Online RRS feed

  • Question

  • To reproduce this problem:

    1. Install Script Lab in both the online and desktop versions of Word.
    2. Create a new code snippet in Script Lab in both Word versions
    3. Copy the following code:
    $("#run").click(() => tryCatch(run));
    async function run() {
      await (context) => {
        const body = context.document.body;
        body.insertHtml("<span style='color: \"#ff0000\";'>Hello</span>", Word.InsertLocation.end);
        await context.sync();
    /** Default helper for invoking an action and handling errors. */
    async function tryCatch(callback) {
      try {
        await callback();
      } catch (error) {
        // Note: In a production add-in, you'd want to notify the user through your add-in's UI.

    The code above uses Range.insertHtml to write some styled text to the current Word document, with the text color set to red.

    When you run this code on the Windows desktop version of Word (Office 365) it adds 'Hello' in red to the document.

    Run the same code in the online version of Word (tested with Chrome and Edge) and you will see that the text 'Hello' is not colored.

    This seems like a bug to me. Could anyone from Microsoft take a look and confirm please?



    Tuesday, April 9, 2019 1:15 PM