Contract Drafting - Area Editing
Function Description
Integrated with business system, dynamically authorize users to edit permissions in specified document areas based on permissions granted by the system.
Usage Instructions: In demo environment, switch selection of content areas between everyone can edit, only I can edit, and I cannot edit, to view changes in area editing permissions.
Code Examples
Example 1: Set all bookmark areas in document to be editable, other areas not editable
async function init() {
app = await ZOfficeSDK.mount(url, selector, true);
await app.ready();
// Enable area editing protection
await app.ActiveDocument.protect(Word.ProtectionType.EditArea);
const bookmarks = await app.ActiveDocument.Bookmarks.toJson();
// Add editable area in each bookmark area, note protection area naming rules
for (const bmName of bookmarks) {
const bookmark = await app.ActiveDocument.Bookmarks.item(bmName);
const range = await bookmark.range;
await app.ActiveDocument.PermMarks.add(
`ProtectionArea_${bmName}`,
{"group": ["everyone"]},
range
);
}
}
Example 2: User selects area, then call SDK API to add editable area
// Initialize
async function init() {
app = await ZOfficeSDK.mount(url, selector, true);
await app.ready();
// Enable area editing protection
await app.ActiveDocument.protect(Word.ProtectionType.EditArea);
}
// Insert editable area in current selection
async function insertEditArea() {
const range = await app.ActiveDocument.getSelection();
await app.ActiveDocument.PermMarks.add(
'ProtectionAreaName',
{"group": ["everyone"]},
range
);
}