如何获取受保护工作表的行数?
我正在使用 Excel._Worksheet.UsedRange.Rows.Count
属性来获取填充行的计数。直到我添加 保护工作表。现在,我的UsedRange返回的值等于每列解锁单元格的长度(100),而不是每列填充单元格的数量(54)。在我保护工作表之前,UsedRange 返回了 54。
我收到
现在,当我调用 ToString() 时,
string columnValue = worksheet.Range[currentColumnString, currentColumnString].Value2.ToString();//currentColumnString = A55, Value2=null
NullReferenceException
这是因为 UsedRange.Rows.Count
是错误的。如何获取受保护工作表的行数?
I am using Excel._Worksheet.UsedRange.Rows.Count
property to get a count of populated rows. This worked up until I added protect worksheet. Now, my UsedRange returns a value equal to the length of the unlocked cells per column (100) instead of the number of populated cells per column (54). UsedRange returned 54 before I protected the sheet.
Now I get
NullReferenceException
when I call ToString()
string columnValue = worksheet.Range[currentColumnString, currentColumnString].Value2.ToString();//currentColumnString = A55, Value2=null
This is because UsedRange.Rows.Count
is wrong. How can I get row counts with a protected sheet?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Excel._Worksheet.Rows.Count
...这些http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.alloweditranges%28v=office.14%29.aspx 可以帮助缩小范围哪些单元格受到保护。try
Excel._Worksheet.Rows.Count
... these http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.alloweditranges%28v=office.14%29.aspx can help to narrow down which Cells are protected.