迭代Excel工作表的行和列并获取值

时间:2011-10-18 22:06:28

标签: .net asp.net vb.net excel

是否可以从Excel.Worksheet的行和列索引中检索单元格的值?我需要遍历所有行和列并获取值...

For row As Integer = 1 To worksheet.UsedRange.Rows.Count
    For col As Integer = 1 To worksheet.UsedRange.Columns.Count
      list.Add(worksheet.Cells(row, col)) 'this doesn't return the value of the cell
    Next
Next

2 个答案:

答案 0 :(得分:0)

尝试:

list.Add(worksheet.Cells(row, col).Value2)

答案 1 :(得分:0)

list.Add(worksheet.Cells(row, col).Value)