Free Support Forum - aspose.com

Unprotect Range in Aspose

Hello,

Please help me how to unprotect cells in named Range.

I have range with name “MyRange”

string rName = “MyRange”;
rangeUnlocked = workbook.Worksheets.GetRangeByName(rName);

I need to unprotect all cells for this range.
How to do this.

Thanks,
pa

@rudolfkalik,

Thanks for your query.

For your information, in the protected worksheet all the cells will have locked (Style.IsLocked) attribute on, so if you want a few cells in the range unlocked, you got to set those cells’ Style.IsLocked to “false”. See the complete document for your reference:
https://docs.aspose.com/display/cellsnet/Protecting+Worksheets

Alternatively, I think you may try to make use of Allow edit range(s) feature for your needs, see the document for your reference:
https://docs.aspose.com/display/cellsnet/Protecting+Worksheets#ProtectingWorksheets-AllowUserstoEditRanges

Hope, this helps a bit.

Hi Amjad,

I need to apply style (false) to range. How to do this?

Style style; // Define the style object.
StyleFlag flag; // Define the styleflag object.
style = ??? //
style.IsLocked = false; // Lock it.
flag = new StyleFlag(); // Instantiate the flag.
flag.Locked = false; // Set the lock setting.

@rudolfkalik,

See the following code segment for your reference:
e.g
Sample code:

...........
 var range = worksheet.Cells.CreateRange("A14:G20");


            for (int r = range.FirstRow; r < range.FirstRow + range.RowCount; r++)
            {

                for (int c = range.FirstColumn; c < range.FirstColumn + range.ColumnCount; c++)
                {
                    Cell cell = worksheet.Cells[r, c];
                    style = cell.GetStyle();
                    style.IsLocked = false;
                    cell.SetStyle(style);

                }

            } 
.............

Hope, this helps a bit.

Thank you for your help.

@rudolfkalik,

Good to know that the suggested code is helpful to you. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.