答案 0 :(得分:0)
Excel数组索引通常基于1,而不是基于0(即,最低元素为数字1)。
var xl = new Microsoft.Office.Interop.Excel.Application();
var b = xl.Workbooks.Open("C:\\Junk\\Junk.xlsx");
Microsoft.Office.Interop.Excel.Worksheet s = b.Worksheets[1]; //1-based
var r = s.Range["A1", "E4"];
int sum = 0;
for (var row = 1; row <= 4; row += 2)
{
sum += r.Value2[row, 1]; //also 1-based
}
xl.Quit();