Set lock true for group of cells

℡╲_俬逩灬. 提交于 2019-12-23 07:57:36

问题


I'm using closedxml to export excel..

Now i can protect (Lock cell) cell using the following function,

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

I want to set group of cells.. Is that Possible in closedxml ?


回答1:


You can use Range like so

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



回答2:


@Raidri, thanks for the answer that 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, or else the lock does nothing.

The worksheet can be protected with workSheet.Protect() method. However, this will have all the cells locked by default, so you'll actually want to protect the worksheet and then unlock the cells you want to be editable.



来源:https://stackoverflow.com/questions/20286191/set-lock-true-for-group-of-cells

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!