而不是采取rowValue.Columns.Value2 我怎么能比较标题,并采取其值在Excel中adin?

我有excel ad-in project ,我fetching values from excel下面的fetching values from excel文件fetching values from excel通过index of sheet row

 rowValue.Columns.Value2[1, 1]; rowValue.Columns.Value2[1, 2]; 

如何获得基于行标题文本的值,而不是提供表格行号?

在这里输入图像描述

我实际上做了我自己的名为GetColumn的VBA函数。 它只是遍历第1行中的每一列,直到它到达具有rsHeading文本的单元格。 只需传入您正在查找的标题的名称,该函数将返回标题的列号。

 Public Function GetColumn(ByRef rsHeading As String) As Long Dim lResult As Long, i As Long lResult = 0 For i = 1 To 255 If Me.Cells(1, i) = "" Then 'end of headings reached' lResult = i ElseIf InStr(Me.Cells(1, i), rsHeading) > 0 Then 'as long as the heading contains the text; it doesn't have to exactly equal that text' lResult = i End If If lResult <> 0 Then Exit For End If Next i GetColumn = lResult End Function 

在你的例子中,我会像这样调用函数:

 rowValue.Columns.Value2[1, GetColumn("Attribute")]; rowValue.Columns.Value2[1, GetColumn("IsMandatory")];