// Load the Excel file
Workbook workbook = new Workbook("sample.xlsx");

// Access the first worksheet
Worksheet sheet = workbook.Worksheets[0];

// Unlock all cells first
Style unlockStyle = workbook.CreateStyle();
unlockStyle.IsLocked = false;

StyleFlag styleFlag = new StyleFlag();
styleFlag.Locked = true;
sheet.Cells.ApplyStyle(unlockStyle, styleFlag);

// Lock specific cells (e.g., A1 and B2)
Style lockStyle = workbook.CreateStyle();
lockStyle.IsLocked = true;

sheet.Cells["A1"].SetStyle(lockStyle);
sheet.Cells["B2"].SetStyle(lockStyle);

// Protect the worksheet to enforce the locking
sheet.Protect(ProtectionType.All);

// Save the modified workbook
workbook.Save("output_locked.xlsx");