Reputation: 21
When you're editing a Word Document, it automatically detect after any update on the file.
I don't find this feature in the Microsoft Documentation, Does it exist ?
Beause, I would like to show a popup (to quit) only if there are modifications.
Currently, i have to compare my two (base64 - string) documents, it seems to be not reliable, i prefere a event.
Thanks
More informations : My code is based with https://learn.microsoft.com/en-us/javascript/api/office/office.document?view=office-js#getfileasync-filetype--options--callback- (getFile)
function _arrayBufferToBase64( buffer ) {
var binary = '';
var bytes = new Uint8Array( buffer );
var len = bytes.byteLength;
for (var i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] );
}
return window.btoa( binary );
}
Upvotes: 1
Views: 2302
Reputation: 25693
I don't know of any event in the COM object model that detects when a Word document is being/has been edited.
There's a Saved
property which can be queried to find out if changes have been made. This doesn't mean, however, that no changes have been made to the document. It only reports whether there are any changes that haven't yet been saved to disk (True = no change pending; False = changes present in memory that haven't yet been saved).
And there's a DocumentBeforeSave
event that notifies when a Save
command has been issued.
The Word JS API also has a Document.Saved
property: https://learn.microsoft.com/en-us/javascript/api/word/word.document?view=office-js#saved
The Office JS APIs have an event BindingDataChanged
that may help. Start here https://learn.microsoft.com/en-us/javascript/api/office/office.eventtype?view=office-js and here https://learn.microsoft.com/en-us/javascript/api/office/office.binding?view=office-js
If it's necessary to know whether any changes have been made, at all, then a comparison is necessary.
Upvotes: 1