Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Tue Aug 23, 2022 2:03 pm

Hi Spire Team,

I have a use case which is I would like to let user to do cell styling, cell editing and insert object but I want to avoid them to delete any column or row.
I have tested:
sheet.Protect("123", SheetProtectionType.All);
<Resulting can do everything including delete col/row>
sheet.Protect("123");
<cannot edit cell value and styling>
sheet.Protect("123", SheetProtectionType.xxxxx);
<will only able to let user to perform either cell styling or adding object etc>

Is there anyway to achieve the use case?
Or any method to exclude DeletingColumns & DeletingRows in SheetProtectionType.All?

Best Regards,
Mshyan

mshyan_spire
 
Posts: 11
Joined: Tue Jul 12, 2022 2:50 am

Wed Aug 24, 2022 7:22 am

Hello mshyan_spire,

Thanks for your inquiry.
You can embed "|" into sheet.Protect() method to set up multiple protection options, as shown my below sample code. If there is still any issue when testing your file, to help us further look into it, please share your file, you can attach it here or send it to us via email(support@e-iceblue.com).

Code: Select all
Workbook workbook = new Workbook();
workbook.LoadFromFile(@"test.xlsx");
Worksheet sheet = workbook.Worksheets[0];
sheet.Protect("123", SheetProtectionType.LockedCells | SheetProtectionType.UnLockedCells|SheetProtectionType.InsertingColumns | SheetProtectionType.InsertingRows );
String result = @"result.xlsx";
workbook.SaveToFile(result, ExcelVersion.Version2013);


Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Wed Aug 24, 2022 3:23 pm

Thanks Simple,

Your solution solved my problem, thanks you.

Best Regards,
Mshyan

mshyan_spire
 
Posts: 11
Joined: Tue Jul 12, 2022 2:50 am

Thu Aug 25, 2022 3:57 am

Hello mshyan_spire,

Thanks for your reply.
You are welcome. If you have any further questions, please feel free to contact us.

Sincerely,
Simple
E-iceblue support team
User avatar

Simple.Li
 
Posts: 248
Joined: Fri Jul 01, 2022 2:33 am

Return to Spire.XLS