none
Insert richtext or html in word online using office app RRS feed

  • Question

  • Hi All, 

    I am trying to insert html text in an content control using an office app from word online and unfortunately it is not working for me. The same code works for me if I run it on the desktop word.

    For Word online some how I can insert only plain text and nothing else. Can anyone please help me with.

     var htmlText = ' <h1>Test HTML Text</h1>'

     var range = context.document.getSelection();

    var myContentControl = range.insertContentControl();
                myContentControl.tag = 'Testtag';
                myContentControl.title = 'TestTitle';

         myContentControl.insertHtml(htmlText, 'end');

      myContentControl.cannotEdit = false;
                myContentControl.cannotDelete = false;

     context.load(myContentControl, 'id');

                // Synchronize the document state by executing the queued commands, 
                // and return a promise to indicate task completion.
                return context.sync().then(function () {
                    console.log('Created content control with id: ' + myContentControl.id);
                });

    Can anyone please help me with what am I missing to achieve the same in word online.

    Wednesday, March 28, 2018 12:41 PM

All replies

  • Hi Anshuman Bansal,

    Try to insert the HTML text directly in .insertHTML with in double quotes to check whether it makes any difference or not.

        myContentControl.insertHtml("text <i>inserted</i> with <b>insertHtml</b>", "before");

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, March 29, 2018 7:26 AM
    Moderator
  • Hi Deepak,

    I have tried this, as I said the problem is that everything works fine for desktop word, but when I run this code on word online nothing happens.

    I have created a word template which is opened from a SharePoint library, may if this can give you more inputs..

    Sunday, April 1, 2018 4:11 PM
  • Hi Anshuman Bansal,

    You had mentioned that,"I have created a word template which is opened from a SharePoint library."

    I think that my testing steps are different then yours.

    I suggest you to provide detailed steps to reproduce the issue.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, April 3, 2018 7:49 AM
    Moderator