add row on protected sheet

Good morning,

if i lock a worksheet as follow

    SpreadTarg.ProtectSheet(SpreadTarg.ActiveSheet, "123")

then i can select sone rows depending on the value in a column and set them as unlocked

  Dim Stile As IStyle = SpreadTarg.ActiveSheet.Range(CElla.Row & ":" & CElla.Row).CellStyle

                                    Stile.Locked = False

The problem is that in this way i can edit the cells in the unlocked row but i can not add any new row.

If modify the protection command as follow

          SpreadTarg.ProtectSheet(SpreadTarg.ActiveSheet, "123", ExcelSheetProtection.InsertingRows=True)

then i can no more unlock any rows nor add new rows.

I tried also with

          SpreadTarg.ProtectSheet(SpreadTarg.ActiveSheet, "123", ExcelSheetProtection.InsertingRows)

but i get the same behaviour.


Please help me,

thank You in advance


Best regards




5 Replies

AR Arulpriya Ramalingam Syncfusion Team September 10, 2021 05:16 PM UTC

Hi Macro, 
 
Thank you for using Syncfusion products. 
 
We suspect that you are trying to protect a workbook with Lock/Unlock and InsertRows options. To avail this behavior the ExcelSheetProtection option can be set to all. Please make use of the below code example. 
 
Example code 
 
//To avail Unlock and InsertRows options. 
spreadsheetControl.ProtectSheet(spreadsheetControl.ActiveSheet, "123", ExcelSheetProtection.All); 
 
Please get back to us if you need any further assistance. 
 
Regards, 
Arulpriya R. 



MD marco del frate replied to Arulpriya Ramalingam September 13, 2021 12:31 PM UTC

Good morning,


i tried Your scode but in that way i can also delete rows and columns while i don't wont it.

I just want to let the operator to insert rows but not to delete them.

Thank You




BT Balamurugan Thirumalaikumar Syncfusion Team September 14, 2021 04:12 PM UTC

Hi marco, 

Thank you for your update. 

We have checked your previous update at our end. Based the on the provided details we assume that you are trying to insert the rows in the protected spreadsheet. If this is the case you can refer the following sample for your reference. We have prepared the simple sample using button click to insert the rows and formatting to the active sheet. You can refer it from below. 


If we misunderstood your query or if you would require any other assistance please let us know. we will be always happy to assist you. 

Balamurugan Thirumalaikumar  




MD marco del frate September 16, 2021 03:02 PM UTC

Good evening,

thank You for our support. In Your sample the worksheet is locked and You can add a row pressing on a button.

This is not what i need. In my case the worksheet has some rows that are completely locked and other whose cells can be edited, and this works. 

More than this, i would like to be free to add rows using the standard control context menu, but at the same time i need that is not possible to add or cancel columns

waiting for Your answer,


Thank You



BT Balamurugan Thirumalaikumar Syncfusion Team September 17, 2021 11:37 AM UTC

Hi marco, 
 
Thank you for your update. 
 
We have checked your previous update at our end. Set the ExcelSheetProtection option to enable if you want to add rows or columns to a protected sheet. You can also set the locked property to false to unclock the range of cells. Please refer the following code snippet and KB for your reference. 
 
//To enable add new row,column and unlocked cells in protectedsheet 
            Spreadsheet.ProtectSheet(Spreadsheet.ActiveSheet, "123", ExcelSheetProtection.InsertingRows | ExcelSheetProtection.InsertingRows | ExcelSheetProtection.UnLockedCells); 
 
 
Please let us know if you would require any other assistance. We will always happy to help you out. 
 
Balamurugan Thirumalaikumar  
 


Loader.
Up arrow icon