isCellLocked() method always returns true

When I try to retrieve a cell’s locked property (via getStyle().isCellLocked()) it always returns true, even though the cell is not locked. I have tested this on 3 different Excel 2003 spreadsheets, all created using Excel, and get the same result every time. Is there something that I am missing? I would expect all cells to have this set to false, unless you were explicity specify within Excel that a cell should be locked. I’ve attached a basic spreadsheet which demonstrates this behavior. Anyone have any ideas?

Thanks.

-Chad


Hi Chad,

Thanks for considering Aspose.

Well, all the cells in a worksheet are (by default) implicitly locked. For confirmation, please check in MS Excel: Right click on any cell (or your desired cell) and click menu option i.e.., Format Cells... Now click Protection tab in the dialogbox, you can see that there is a checkbox named Locked which is checked by default. So, isCellLocked will always return true unless you uncheck the Locked checkbox.

I have checked your template file and all cells in all the worksheets are locked, so isCellLocked will always return true as I tested it with the following code using your template file:

Sample code:

Workbook workbook = new Workbook();
workbook.open("e:\\Files\\Hello.xls");
Worksheets worksheets = workbook.getWorksheets();
Worksheet worksheet = worksheets.getSheet(0);
System.out.println(worksheet.getCells().getCell("E9").getStyle().isCellLocked());

And for your info, locking cells has no effect unless you protect a worksheet. Please check the following doc that defines how to protect the whole worksheet, a few cells in a worksheet, a few rows in a worksheet and a few columns in a worksheet etc. using the Aspose.Cells APIs. The topic will give you some insight about locking cells and protecting worksheets:

http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/protecting-worksheets.html

Thank you.

Thanks! That definitely answered my question.

-Chad