Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Protect a Workbook

The following code protects workbook structure with a password (“password”), preventing end-users from adding or deleting worksheets, and from displaying hidden worksheets.

View Example

// Protect workbook structure (prevents users from adding or deleting worksheets
// or from displaying hidden worksheets).
workbook.BeginUpdate();
if (!workbook.IsProtected)
    workbook.Protect("password", true, false);
workbook.Worksheets[0].Visible = false;
Worksheet worksheet = workbook.Worksheets[1];
worksheet["D5"].Value = "You are not allowed to add or delete a worksheet.";
worksheet["D6"].Value = "Hidden worksheets cannot be displayed.";
workbook.EndUpdate();

Use the IWorkbook.Unprotect method to remove protection.

When protection is applied programmatically, end-users can invoke the Protect Workbook Dialog to remove protection.

See Also