Foxtable(狐表)用户栏目专家坐堂 → 代码优化


  共有4395人关注过本帖树形打印复制链接

主题:代码优化

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


加好友 发短信
等级:小狐 帖子:337 积分:3225 威望:0 精华:0 注册:2020/2/25 23:12:00
代码优化  发帖心情 Post By:2022/5/16 22:54:00 [只看该作者]


           以下代码执行要10多秒,还有能优化的地方吗( 其中表A有900行,SHEET有2万多行)

 

             Dim Book As New XLS.Book(路径1)   
                        Dim Sheet As XLS.Sheet = Book.Sheets(0)
                        For Each dr3 As DataRow In DataTables("表A").Select("编码 is not  null  ")                          
                            For n As Integer = 0 To Sheet.Rows.Count -1
                                If sheet(n,1).VALUE = dr3("编码")   Then
                                    dr3("单价")= sheet(n,2).VALUE
                                    Exit For
                                End If
                            Next
                        Next


 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111412 积分:567130 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2022/5/16 23:17:00 [只看该作者]

试试

Dim Book As New XLS.Book(路径1) 
Dim Sheet As XLS.Sheet = Book.Sheets(0)
Dim dict As New Dictionary(Of String, Double)
For n As Integer = 0 To Sheet.Rows.Count - 1
    dict.Add(sheet(n, 1).VALUE, sheet(n, 2).VALUE)
Next

For Each dr3 As DataRow In DataTables("表A").Select("编码 is not  null  ") 
    If dict.ContainsKey( dr3("编码")) Then
        dr3("单价") = dict( dr3("编码"))
    End If
Next

 回到顶部