Reputation: 2470
I am developing an excel web app add-in for office365, my excel file is placed in one drive. When I open my excel file it shows in read-only mode. Is it possible using office.js or any javascript code to detect if a file is in read-only?
I tried url in the browser changes if you edit the excel so that can be used to detect if a file is in read-only mode or edit mode. right now you can see it as view.aspx page.
I also tried using window.location
, but as this app stays in an iframe, it's difficult to get parents url location.
Upvotes: 0
Views: 324
Reputation: 33094
You can use the Document.mode property to determine if a file is Read Only. This property returns either readOnly
or readWrite
. It is supported across Word, Excel and PowerPoint on Desktop and Online.
Upvotes: 0
Reputation: 14649
There is no such API we can detect the Office model at present. You may consider to try to set the value to the selected cell to see whether it could work as a workaround. For example, it it is read-only mode, the set data action would failed.
Here is an example for your reference:
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text, function (asyncResult) {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
Office.context.document.setSelectedDataAsync(asyncResult.value, function (asyncResult) {
app.showNotification(asyncResult.status);
})
}
})
And if you want the Office add-in to support this feature, you may submit the feedback here.
Upvotes: 1