[英]loop through range object excel c#
Using interop for c# I have a range object as follows: 对于c#使用互操作,我有一个范围对象,如下所示:
Range rangeAToV = ws.get_Range("A1", "V1");
and I'm trying to do this: 我正在尝试这样做:
foreach (var cell in rangeAToV.Cells)
{
}
is this wrong? 这是错的吗? I'm trying to set cell.value2
but that's now showing up. 我正在尝试设置cell.value2
但现在正在显示。
The collection object to iterate through is the Range
itself, not the Cells
property: 要迭代的集合对象是Range
本身,而不是Cells
属性:
foreach (Range cell in rangeAToV)
{
// Do stuff with cell.
}
I found a solution that isn't giving me an issue: change "var cell"
in the loop to: 我找到了一个不会给我带来问题的解决方案:将循环中的"var cell"
更改为:
foreach (Range cell in rangeAToV) {
//stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.