OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
686 stars 95 forks source link

Disable document editing using Office JavaScript API #5074

Open rahul-chanana opened 1 day ago

rahul-chanana commented 1 day ago

Hello,

We are developing an Office Add-In (Taskpane) using the Angular framework and are looking for a way to set the document to read-only or disable editing using the Office JavaScript API. Our Add-In performs logic that may take a significant amount of time, and we are seeking a method to lock the document during this process.

We couldn't find any equivalent methods in the available APIs. Is there any way to achieve this?

Thank you in advance for your help!

Expected Behavior

We would like to disable editing of the document temporarily using the Office JavaScript API and enable editing again once the process is complete.

Current Behavior

There doesn't seem to be a method available in the API to disable editing of the document.

Context

We need to perform long-running logic in the add-in, and during this time, we need to disable editing of the document.

Your Environment

RuizhiSunMS commented 1 day ago

Hi @rahul-chanana, thx for your submit. The excel has a feature called worksheet protection. Is this what you want? https://learn.microsoft.com/en-us/javascript/api/excel/excel.worksheetprotection?view=excel-js-preview

rahul-chanana commented 1 day ago

Hi @RuizhiSunMS,

Thanks for your reply. I’ve tested the worksheet protection, and it’s working well. We now need similar APIs for Word and Powerpoint as well. Is there any way to achieve this functionality in Word and Powerpoint as well?

RuizhiSunMS commented 1 day ago

Hi @RuizhiSunMS,

Thanks for your reply. I’ve tested the worksheet protection, and it’s working well. We now need similar APIs for Word and Powerpoint as well. Is there any way to achieve this functionality in Word and Powerpoint as well?

I'm investigating.

EsterBergen commented 1 day ago

@rahul-chanana -

Currently, the Office JavaScript API does not provide a direct method to disable document editing or set a PowerPoint presentation to read-only model.

However, you might consider alternative approaches, such as:

  1. Prompting the user to save and close the document before performing operations that require the document to be in a non-editable state.
  2. Using dialogs or notifications to inform users not to make changes during certain operations.
  3. Implementing custom logic to track changes and revert them if necessary, though this can be complex and may not fully prevent editing.

If you'd like to request a feature - please make the request here Microsoft 365 Developer Platform Ideas Forum. Feature requests on are considered when we go through our planning process. Thanks for highlighting this!