none
Word Online: OBJ characters get inserted in a document having fields RRS feed

  • Question

  • Hi,

    I am creating a word addin which requires to get current selection

    In Word Online if I upload the document containing fields and select data between fields and query getSelection API. OBJ characters get inserted in document

    Attached sample document and video recording of issue:

    https://spaces.hightail.com/receive/bYlBCeLCTe

    Steps to reproduce

    1. Open Word Online

    2. Upload document containing fields(Download from above URL)

    3. Run the below code

    4. Refresh document

    5. Observe fields property is lost and OBJ character get inserted.

    // Run a batch operation against the Word object model.
    Word.run(function (context) {
    
        var textSample = 'This is an example of the insert text method.';
    
        // Create a range proxy object for the current selection.
        var range = context.document.getSelection();
    
        // Queue a commmand to insert text at the end of the selection.
        range.insertText(textSample, Word.InsertLocation.end);
    
        // Synchronize the document state by executing the queued commands, 
        // and return a promise to indicate task completion.
        return context.sync().then(function () {
            console.log('Inserted the text at the end of the selection.');
        });  
    })
    .catch(function (error) {
        console.log('Error: ' + JSON.stringify(error));
        if (error instanceof OfficeExtension.Error) {
            console.log('Debug info: ' + JSON.stringify(error.debugInfo));
        }
    });

    Thanks,
    Abhijeet


    Thursday, October 4, 2018 10:04 AM

All replies

  • Hi Abhijeet,

    I have used the document that you provided and follow the steps in your video but still can't reproduce your problem. 

    Please take a look at the gif that i recorded:

    To avoid this kind of problems, try to test it on another computer.

    Best Regards,

    Yuki


    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.


    Friday, October 5, 2018 5:12 AM
    Moderator
  • Hi Yuki,

    You could reproduce it!
    Look at your animation you posted closely.

    After refreshing, the last word in the document "manday" has lost its field property which is not desired.
    The document has been corrupted.

    Go ahead an open the document in Desktop word, you will see the field has disappeared. and if you fetch the OOXML for the document you will see the OBJ character. 

    Thanks,
    Abhijeet


    Monday, October 8, 2018 5:58 AM
  • Hi Abhijeet,

    Sorry for the late reply.

    I can observe that the last word in the document "manday" has not been selected like it does at beginning.

    Is that the field property you mentioned above?

    Also I still can't reproduce the OBJ character as you shown on the video.

    >> And if you fetch the OOXML for the document you will see the OBJ character. 

    I'm confused what does it mean.

    Does it mean we can see the OBJ character when using Office Open XML to open the document.xml?

    Best Regards,

    Yuki


    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.

    Thursday, October 11, 2018 8:31 AM
    Moderator
  • Hi Yuki,

    Yes, the word "manday" was a field. It wasn't editable at beginning, but after running the above mentioned code it looses its field properties and becomes editable. In short the API document.getSelection() corrupts the document.

    To see the OBJ character you can fetch Word Open XML by running below code once the document is corrupted.

    Word.run(function (context) {
        
        var bodyOOXML = context.document.body.getOoxml()
    	
        return context.sync().then(function () {		
            console.log(bodyOOXML.value);		
        });  
    })
    .catch(function (error) {
        console.log('Error: ' + JSON.stringify(error));
        if (error instanceof OfficeExtension.Error) {
            console.log('Debug info: ' + JSON.stringify(error.debugInfo));
        }
    });

    Copy it some good text editor like Notepad++ and look for OBJ character in it.

    My overall concern is document.getSelection() API is corrupting user document.
    Do you know any other workaround or API to getSelection from document?

    Thanks,
    Abhijeet

    Thursday, October 11, 2018 10:17 AM
  • Hi Abhijeet,

    We reproduced your question, thanks for your detail information.

    We will get back to you if any updates.

    Best Regards,

    Yuki


    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.


    Monday, October 15, 2018 9:33 AM
    Moderator