c# - Protect UserInterfaceOnly and EnableOutlining -


i creating addin excel. protecting sheets in workbook:

public static void protectsheetui(_worksheet sheet, string password) {     sheet.enableoutlining = true;     sheet.protect(password, contents: true, userinterfaceonly: true, allowformattingcells: true,         allowformattingcolumns: true, allowformattingrows: true); } 

but problem when close , reopen workbook, grouping/ungrouping doesn't work. because userinterfaceonly not persistent. in workbook level, unprotect , protect sheets again when being opened. how can achieve add-in?

the userinterfaceonly setting not saved when close workbook. have reset when workbook opened. best place in workbook_open event procedure. need handle in add-in. example (doing memory please ignore typos/syntax errors)

private void thisaddin_startup(object sender, system.eventargs e) {     this.application.workbookopen +=      new excel.appevents_workbookopeneventhandler(application_workbookopen); }  void application_workbookopen(excel.workbook wb) {    //~~> rest of code } 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -