Disable adding, delete and renaming worksheet functionality

Hi Team,

I want to disable the functionality of adding, deleting and renaming of existing sheets in excel.

Platform : .Net
Used Aspose.Cells version : 19.9.0

image.png (3.7 KB)

Happy Coding,
Thanks :slight_smile:

@sachinmali26,

How could you do this in MS Excel manually? You may accomplish the task manually in MS Excel and share the sample Excel file (you may zip prior attaching here). We will check it on how to do it via Aspose.Cells APIs.

May be you could hide the sheet tab (bar) for your needs. See the documenthttps://docs.aspose.com/cells/net/show-and-hide-worksheets-and-tabs/#hiding-tabs for your reference.

1 Like

adddeleterename_sheet.zip (8.1 KB)
Hi @Amjad_Sahi,

Thanks for response,
My all 3 sheets are protected but still I am able to add, delete and rename sheets

I have attached sample excel with protected sheets.
----------------------------------Dummy Code---------------------
for (int i = 0; i < 3; i++)
{
workbook.Worksheets.Add();
workbook.Worksheets[i].Name = “DummySheet_” + i;
workbook.Worksheets[i].Protect(ProtectionType.All, “test”, null);
}

Thanks,
Happy Coding :slight_smile:

@sachinmali26,
You may please try the following code that will restrict adding, deleting and renaming a worksheet in the workbook.

//Open the excel file.
Workbook workbook = new Workbook();

//Protect the workbook specifying a password with Structure and Windows attributes.
workbook.Protect(ProtectionType.All, "007");

//Save As the excel file.
workbook.Save(@"MyBook.xlsx");
1 Like

Hi @ahsaniqbalsidiqui,

Resolved :slight_smile:
Just I need to protect excel on workbook level instead of worksheet level.
e.g.
Instead of
workbook.Worksheets[i].Protect(ProtectionType.All, "test", null); //not working
It will work when we apply protection on workbook level
workbook.Protect(ProtectionType.All, "text"); //working

Thanks :slight_smile:

@sachinmali26,
We are glad to know that your issue is resolved. Please feel free to write us back if you have any other query in this regard.