2
votes

i want to know if there is any API/function which can be used to detect if office document is read-only. I am creating an office add-in using office.js library. the document is shared to other user in readonly mode. if i use following property, it shows readWrite but actually document is in readonly mode. following property is not helping

var docMode = Office.context.document.mode; // did not work, it gives value of manifest file i guess

I am trying following thing, it worked but not sure if that is the right approach. if the file is in one drive it give url as http://d.doc.onedrive..something like this.

if (Office.context.document.url.indexOf("https://excel.officeapps.live.com") > -1) {// its in read-only mode-this is the unique folder name where the file is 
            $("#container").show();
            $("#readOnlyArea").show();
        } else {
            $("#mainArea").show();}
1
Let me follow up on that. Could you try this out in both Excel desktop and online, and check what the return values of Office.context.document.mode are for both read-write and read-only documents?Michael Zlatkovsky - Microsoft
that value doesnot work. it give the answer as readWrite (i think it gets that value from manifest) even if its not writable. i have tried that. btw i have sent you email about this on your gmail id..i will update that here.shyam_
OK, I'll ask someone on my team...Michael Zlatkovsky - Microsoft
hi Michael, can you help me with this question also..stackoverflow.com/questions/38492972/…shyam_

1 Answers

1
votes

It is a really good question. Since Excel has the very interesting scratch mode, basically even though Excel is in read only mode. Both users and add-ins are still able to write to the workbook. Therefore this API always returns ReadWrite meaning the add-in is able to write. The current behavior is by design. However, these changes can't be saved for read only files. We are aware this is a gap and we have added it to our backlog. Thanks for raising this issue.

Thanks, Sky