老师好,下面代码是通过自定义函数寻找Excel文档中某个单元格的行与列信息Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter = "Excel文件|*.xls;*.xlsx;*.xlsm" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim Book As New XLS.Book(dlg.FileName)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim ar() As String = Functions.Execute("测试", sheet, "序号")
Output.show(ar(0) & " " & ar(1))
End If
自定义函数代码如下 (自定义函数名为 测试)
Dim Ws As XLS.Sheet = Args (0)
Dim Key_Word As String = Args (1)'需要查找的单元格的关键字
Dim arr() As String
Dim r As Integer = Ws.Rows.Count
Dim c As Integer = Ws.Cols.Count
For i As Integer = 1 To r
For j As Integer = 1 To c
Dim s As String = Ws (i, j).Value
If s = Key_Word Then
arr(0) = r
arr(1) = c
Exit For
End If
Next
Next
Return arr
执行时出现错误
请老师帮忙给看下。 谢谢!