Cell Locking not working

Hello Team,

I was trying to set Locked property of a cell using following code snippet from the Aspose examples -

Workbook excel = new Workbook(dataDir + "Book1.xlsx");

		WorksheetCollection worksheets = excel.getWorksheets();
		Worksheet worksheet = worksheets.get(0);

		worksheet.getCells().get("A1").getStyle().setLocked(true);

		// Saving the modified Excel file Excel XP format
		excel.save(dataDir + "LockCell_out.xlsx");

But this is not working …
Before executing the above code I created new blank Book1.xlsx file. Opened it and set the “Locked” property under protection tab of format cell of cell “A1”

Then I Executed Above code which created LockCell_out.xlsx file

When I opened LockCell_out.xlsx after executing above code I can still see the “Locked” does not get checked under the protection tab of format cell menu for Cell A1.

Can you please let me know what I am missing here ?
Regards
Mukul

@mukulpurohit,

Please note, by default for a worksheet, “Locked” option (in “Format Cells…” dialog box, click the Protection tab ) of all the cells are checked/locked, so you don’t need to check the option in code by any means. However, if you need some ranges of cells should not be locked, you may set this option unchecked via code. Please note, in any case, to protect a worksheet, you have to use Worksheet.protect() method to implement the locking. To protect whole worksheet, a few cells only, entire row only or entire column only, see the document on protecting worksheets with examples for your complete reference.

In case, you still have any issue or confusion, let us know with details, sample Excel file and code snippet. We will then check and assist you soon.

PS. please zip the files prior attaching.