Foxtable(狐表)用户栏目专家坐堂 → 处理EXCEL


  共有9331人关注过本帖平板打印复制链接

主题:处理EXCEL

帅哥哟,离线,有人找我吗?
wh420
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1107 积分:10586 威望:0 精华:0 注册:2014/2/19 16:32:00
  发帖心情 Post By:2021/5/10 16:41:00 [只看该作者]

比如标红这几处怎么定义变量?在外面会定义,但函数里与函数外是怎么个对应关系搞不懂。
如:要定义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


 回到顶部
总数 108 1 2 3 4 5 6 7 8 9 10 下一页 ..11