Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从for循环中获取Excel的单元格范围_C#_Excel - Fatal编程技术网

C# 如何从for循环中获取Excel的单元格范围

C# 如何从for循环中获取Excel的单元格范围,c#,excel,C#,Excel,我试图获取for循环中指定的值,然后将它们用作从Excel获取的单元格范围。这里出了什么问题 List<string> str = new List<string>(); // The follwing increments by 4, and starts at 25 for (int i = 25; i <= lastRow; i += 4) // += means a + b { st

我试图获取for循环中指定的值,然后将它们用作从Excel获取的单元格范围。这里出了什么问题

List<string> str = new List<string>();

        // The follwing increments by 4, and starts at 25

        for (int i = 25; i <= lastRow; i += 4) // += means a + b
        {
            str = ws.Range["B"+i].Value;
         }

)

我认为你的问题应该澄清,但这可能会有帮助:

for (int i = 25; i <= lastRow; i += 4) // += means a + b
{
    string cellName = "B" + i.ToString();
    string cellValue = (string)ws.Range[cellName].Value;
    str.Add(cellValue);
}

for(int i=25;i是ws a
列表的值
?你能详细说明你的问题是什么吗?我不明白你想达到什么目的
for (int i = 25; i <= lastRow; i += 4) // += means a + b
{
    string cellName = "B" + i.ToString();
    string cellValue = (string)ws.Range[cellName].Value;
    str.Add(cellValue);
}