比如标红这几处怎么定义变量?在外面会定义,但函数里与函数外是怎么个对应关系搞不懂。
如:要定义WS和WB怎么定义?
Dim Ws As MSExcel.WorkSheet=Wb.WorkSheets(k) '这个变量K是函数外面For k As Integer=1 To wb.worksheets.Count循环的,而WB是Dim wb=app.WorkBooks.open(file)来的,
怎么带进到函数中,老师给举个例子呗。
RowsMax = 0
ColsMax = ws.UsedRange.columns.count
'获取最大行
For i As Integer = 1 To ColsMax
Dim r = ws.cells(excelrows,i).End(MsExcel.XlDirection.xlUp).Row
If r > RowsMax Then
RowsMax = r
End If
Next
'获取最大列
For i As Integer = 1 To RowsMax
Dim r = ws.cells(i,excelcol).End(MsExcel.XlDirection.xlToLeft).Column
If r > ColsMax Then
ColsMax = r
End If
Next
Else
RowsMax = Numcb1.Value
ColsMax = Numcb2.Value
End If
Dim rg As MSExcel.Range = Ws.Range(Ws.Cells(1,1), Ws.Cells(RowsMax,ColsMax))
If rg.Count = 1 And rg(1).Value Is Nothing Then
Continue For
End If
Dim ary = rg.value
For i As Integer=1 To RowsMax
For j As Integer = 1 To ColsMax
If ary(i, j) <> Nothing AndAlso Typeof ary(i,j) Is String AndAlso dic.ContainsKey(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), "")) Then
lbl11.text= "Sheet名称:" & ws.name
rg(i, j).Value= dic(ary(i,j).ToLower.Replace(" ","").Replace(chr(10), "").Replace(chr(13), ""))
End If
Next
Next