@Raidri, thanks for the answer you provided here, but I want to add my own answer.
I found that when you want to lock a cell, the worksheet must first be protected, otherwise the lock does nothing.
A worksheet can be protected using the workSheet.Protect() method. However, by default, all blocks will be locked, so you really want to protect the worksheet, and then unlock the cells that you want to edit.
source share