Hi,
Thanks for your posting and using Aspose.Cells for Java.
Please see the following documentation article for your help.
https://docs.aspose.com/cells/java/protect-and-unprotect-worksheet/
The following example exhibits how to protect a
few cells in the worksheet. It unlocks all the cells in the worksheet
first and then locks 3 cells (A1, B1, C1) in it. Finally, it protects
the worksheet. A row / column has a Style API that further contains a set Locked method . You can use this method to lock or unlock the row / column.
Java
// Create a new workbook.
Workbook wb = new Workbook();
// Create a worksheet object and obtain the first sheet.
Worksheet sheet = wb.getWorksheets().get(0);
// Define the style object.
Style style;
// Loop through all the columns in the worksheet and unlock them.
for(int i = 0; i <= 255; i ++)
{
style = sheet.getCells().getColumns().get(i).getStyle();
style.setLocked(false);
sheet.getCells().getColumns().get(i).setStyle(style);
}
// Lock the three cells…i.e. A1, B1, C1.
style = sheet.getCells().get(“A1”).getStyle();
style.setLocked(true);
sheet.getCells().get(“A1”).setStyle(style);
style = sheet.getCells().get(“B1”).getStyle();
style.setLocked(true);
sheet.getCells().get(“B1”).setStyle(style);
style = sheet.getCells().get(“C1”).getStyle();
style.setLocked(true);
sheet.getCells().get(“C1”).setStyle(style);
// Save the excel file.
wb.save(“d:\test\lockedcells.xls”, FileFormatType.EXCEL_97_TO_2003);