However, I am importing an existing XSLX to which I am applying the above logic.
The code you provided created a cell (with the String “locked”) which is now non-editable.
I tried, unsuccessfully, to apply this to existing cells using getCell().
Do you have to create a new cell in order to make it locked, and in turn copy all value/style/formula across? I would have thought there is a way to do this to an existing cell.
If the spreadsheet component is based on apache poi (which it looks like it is), then functions like getCell(…) and getRow(…) can return null if that cell / row is empty. You’ll need to check for null returns and if so then create that cell / row.