none
Event onChanges RRS feed

  • Question

  • Hello,

    I am working on Add-in (Office Js – Angular 5); I’ am looking for a good way to know if a document have been changed.

    Currently, I get my document from an API, (string base64) so I cannot use saved property/event. (I do not know why but I cannot use “insertFileFromBase64” with the returned string (System.Convert.ToBase64String from c#).

    To test my code, I am using “getFileAsync” and the methods in example from docs.microsoft (to get the document in base64), then I make a copy in a new variable, I do it again (without change) and I save it in an another new variable.

    To know if there are any changes, I compare descriptions but it’s never the same. 

    (Maybe it come from the encoding) : 

      public _arrayBufferToBase64( buffer ) {
          var binary: string = '';
          var bytes: Uint8Array = new Uint8Array( buffer );
          var len: number = bytes.byteLength;
          for (var i = 0; i < len; i++) {
              binary += String.fromCharCode( bytes[ i ] );
          }
          return window.btoa( binary );
      }

    Therefore, I cannot use this way to catch any changes in my document.

    I do not like “BindingDataChangedEventArgs” because I am afraid about the possibility that the user write outside the binding.

    Does it have a binding like property on all document (without any appearance on Word)?

    Thanks,

    B.

    Friday, January 25, 2019 10:40 AM

All replies

  • Cross-posted at: https://stackoverflow.com/questions/54151595/detect-changes-on-word-api-office
    For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184

    As you were advised there, you can test the Document.Saved state: if True it has not been changed since whenever it was last saved; if False it has been changed since then. There is also a DocumentBeforeSave event you can use in conjunction with that to test whether the document has been saved at any time since your code opened it.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, January 25, 2019 11:07 AM
  • Sorry for the cross-posted, thank for the link.

    Thanks for the answer. 

    Maybe I am wrong or misunderstand; I never save a document (with Word), my application send it back to an API. “Saved” will return false in each cases same as “DocumentBeforeSave” will be never trigger because: “that notifies when a Save command has been issued”.

    Moreover, saved property is in a “read only” state so I can change it to true after an insert.

    May I ask some questions?

    • I cannot find information about insert mailings in word (Add-in), is it possible?
    • What could be a possibility of that a string (base64 .docx) obtained with toBase64String cannot be use with “insertFileFromBase64 whereas it can create a doc file from it in c#?

    Thanks,

    B




    • Edited by ByssyB Friday, January 25, 2019 4:27 PM
    Friday, January 25, 2019 4:26 PM
  • You cannot change the Document.Saved property - Word does that automatically as soon as a change is made. The document then retains that state until it is next saved.

    Questions about other issues should be asked in separate threads - one thread per issue.


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Friday, January 25, 2019 11:07 PM