[英]Locking/Unlocking merged Excel cells using C# and WPF
I'm trying to unlock a couple of cells using the code below. 我正在尝试使用下面的代码解锁几个单元格。 The cells are merged with each other and I don't want to disjoin them as I am working on a client's quote template and do not want to change his quote structure :) Anyway...here is the code:
单元格彼此合并,我不想将它们分开,因为我正在处理客户端的报价模板,并且不想更改其引用结构:)无论如何......这里是代码:
Excel.Worksheet ws = wb.Worksheets[1];
ws.Range["F25:F42"].Locked = false; //Error here
I get an error saying: 我收到一个错误说:
We can't do that to a merged cell.
我们不能对合并的单元格这样做。
Is there a way of getting around this error so that I can unlock/lock the cells as I will? 有没有办法解决这个错误,以便我可以解锁/锁定单元格?
I suggest doing this: 我建议这样做:
Excel.Worksheet ws = wb.Worksheets[1];
foreach (Excel.Range ra in ws.Range["F25:F42"]) {
ra.MergeArea.Locked = false;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.