Set true lock on a group of cells

I use closedxml to export excel ..

Now I can protect (block a cell) a cell using the following function,

workSheet.Cell(rowIndex,column).Style.Protection.SetLocked(true); 

I want to set a group of cells. Is this possible in closedxml?

+8
source share
2 answers

You can use Range so

 workSheet.Range(startRow, startColumn, endRow, endColumn).Style.Protection.SetLocked(true); 
+7
source

@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.

+7
source

Source: https://habr.com/ru/post/959042/


All Articles