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

时间:2013-02-15 15:01:18

标签: 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
        {
            str = ws.Range["B"+i].Value;
         }

...

 SeriesCollection seriesCollection_mySeries = xlChart.SeriesCollection();
 Series series1 = seriesCollection_mySeries.NewSeries();

 series1.Values = str

1 个答案:

答案 0 :(得分:0)

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

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);
}