Hi,
My requirement was to lock all the cells on the sheet but make some of the cells editable in the sheet
Now on clicking the locked/protected/read-only cells. it is showing the dialog box with message (The cell you are trying to change is protected. to make change unprotect the sheet) and I don't want to show this dialog box I just want to make the cells readonly so that user can't edit it. This dialog box is bothering me a lot. how to discard it when user clicks on the cells which are locked/protected?
See the attachments if it can help you in better understanding.
Thanks in advance.
Waiting for your response.
Thanks,
Vaishali Jain
Hi Vaishali Jain,
We have checked your reported query and would like to let you know that the dialog box can be discarded on clicking a protected cell.
And this can be achieved by setting args.cancel to true, if the dialog is protect sheet dialog in the dialogBeforeOpen event of our spreadsheet.
For your convenience, we have prepared a local sample and attached along with the code snippet below for your reference.
Code Snippet:
export class AppComponent { constructor() { } @ViewChild('default') public spreadsheetObj!: SpreadsheetComponent; public data: Object[] = getDefaultData();
created() { this.spreadsheetObj.cellFormat( { fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:F1' ); //To protect the worksheet. let protectSetting: ProtectSettingsModel = { selectCells: true, selectUnLockedCells: true }; this.spreadsheetObj.protectSheet('Car Sales Report', protectSetting); const unlockedRanges = ['H10', 'H11', 'H12', 'H13', 'H14', 'H15', 'H16'];
// Specify the ranges or cells you want to unlock unlockedRanges.forEach((range: any) => { if (this.spreadsheetObj) { this.spreadsheetObj.lockCells(range, false); } }); }
dialogBeforeOpen(args: DialogBeforeOpenEventArgs) { // Checking whether dialog protect sheet if (args.dialogName === "EditAlertDialog" ) { args.cancel = true; } } } |
Sample Link: Please refer to the attachment below.
In the sample above, we have checked whether the dialog box is the protect sheet dialog then, we discard the dialog box by setting args.cancel to true in the dialogBeforeOpen event of our spreadsheet.
For your convenience, we have prepared a video demonstration of the above case and attached below for your reference.
Video Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Video-F188547-57453139
For more information on sheet protection, please refer the UG link mentioned below
Kindly, check the above information and get back to us for further clarifications
Regards,
Dinakar M
Hi Dinakar Manickam,
Thanks for the help. It's working.