We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Lock cells not working with version

With version of Aspose.Cells.dll it worked to lock cells with the following code.

Aspose.Cells.Style style = workbook.Styles[workbook.Styles.Add()];
style.Font.Size = 10;
style.IsLocked = true;
style.Name = "ReadOnlyClass";

style = workbook.Styles[workbook.Styles.Add()];
style.Font.Size = 9;
style.IsLocked = false;
style.Name = "EditableClass";

range = sheet.Cells.CreateRange(0, 0, 2, 2);
styleFlag = new StyleFlag();
styleFlag.All = true;
range.ApplyStyle(workbook.Styles["ReadOnlyClass"], styleFlag);

range = sheet.Cells.CreateRange(3, 0, 2, 2);
styleFlag = new StyleFlag();
styleFlag.All = true;
range.ApplyStyle(workbook.Styles["EditableClass"], styleFlag);

sheet.Protection.IsDeletingColumnsAllowed = false;
sheet.Protection.IsDeletingRowsAllowed = false;
sheet.Protection.IsEditingContentsAllowed = false;
sheet.Protection.IsEditingObjectsAllowed = false;
sheet.Protection.IsEditingScenariosAllowed = false;
sheet.Protection.IsFilteringAllowed = false;
sheet.Protection.IsFormattingCellsAllowed = true;
sheet.Protection.IsFormattingColumnsAllowed = true;
sheet.Protection.IsFormattingRowsAllowed = true;
sheet.Protection.IsInsertingColumnsAllowed = false;
sheet.Protection.IsInsertingHyperlinksAllowed = false;
sheet.Protection.IsInsertingRowsAllowed = false;
sheet.Protection.IsSelectingLockedCellsAllowed = true;
sheet.Protection.IsSelectingUnlockedCellsAllowed = true;
sheet.Protection.IsSortingAllowed = false;
sheet.Protection.IsUsingPivotTablesAllowed = false;
sheet.Protection.Password = "hello";

Now with version all cells i locked even the ones with the style EditableClass where style.IsLocked = false;

Please tell me how to only lock certain cells.

This message was posted using Aspose.Live 2 Forum


I have tried your scenario with the latest version/fix v5.1.2.2 (attached) and it works fine.

Please try the attached version.

Thank you.

Thank you for your reply.

Unfortunately, our license has expired so I can not use the latest version right now.
Doesn’t my example work with version or am I doing something wrong?


I am afraid, you need to use our latest version/fix.

Please try our latest version, you may comment the licensing code and check if it works fine with it.


Amjad Sahi


I have now tested with version and found something that seems strange.
The following code makes cell B1 editable but cell C1
remains locked.

It seems that adding a name to a style makes locked = false not work.

Workbook workbook = new Workbook();
Aspose.Cells.Worksheet sheet = workbook.Worksheets[0];

sheet.Cells[0, 1].PutValue(“Editable1”);
sheet.Cells[0, 2].PutValue(“Editable2”);

Aspose.Cells.Style styleWorking = workbook.Styles[workbook.Styles.Add()];
styleWorking.IsLocked = false;
styleWorking.Font.Color = System.Drawing.Color.Green;
sheet.Cells[0, 1].SetStyle(styleWorking);

Aspose.Cells.Style styleNotWorking = workbook.Styles[workbook.Styles.Add()];
styleNotWorking.IsLocked = false;
styleNotWorking.Font.Color = System.Drawing.Color.Red;
styleNotWorking.Name = “EditableCell”;
sheet.Cells[0, 2].SetStyle(styleNotWorking);

sheet.Protection.AllowEditingContent = false;

workbook.Save(this.Response, “test.xlsx”, ContentDisposition.Attachment, new OoxmlSaveOptions());


After an initial test, I can find the issue as you have mentioned using your sample code. I have logged your issue into our issue tracking system with an id: CELLSNET-19536. We will figure it out soon.

Thank you.


Please use the updated version of Aspose.Cells.dll v5.1.2.3. The issue has been resolved.


The issues you have found earlier (filed as 19536) have been fixed in this update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.