shyam_
shyam_

Reputation: 2470

how to detect if excel file open from one drive is readonly using office.js

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?

enter image description here

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

Answers (2)

Marc LaFleur
Marc LaFleur

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

Fei Xue
Fei Xue

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

Related Questions