Foxtable(狐表)用户栏目专家坐堂 → [求助]下面这段 代码如何优化?


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

主题:[求助]下面这段 代码如何优化?

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


加好友 发短信
等级:狐神 帖子:5015 积分:25363 威望:0 精华:0 注册:2015/8/18 9:21:00
  发帖心情 Post By:2016/8/16 9:02:00 [显示全部帖子]


Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "excle|*.xlsx" '设置筛选器

If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim Book As New XLS.Book(dlg.FileName)
    Dim Sheet As XLS.Sheet = Book.Sheets(0)
    Dim t As Table = Tables("工资总表导入")
    t.StopRedraw()
    Dim c As Integer = t.Rows.Count
    Dim dict As new Dictionary(of Integer,String)
    For sc As Integer = 0 To sheet.Cols.Count -1
        If t.Cols.Contains(sheet(0,sc).Value) Then
            dict.Add(sc,sheet(0,sc).Value)
        End If
    Next
    
    For sr As Integer = 1 To sheet.Rows.Count -1
        Dim r As Row = t.AddNew
        For Each i As Integer In dict.Keys
            r(dict(i)) = sheet(sr,i).Value
        Next
    Next
    t.ResumeRedraw()
    MessageBox.Show("导入完成,共导入" & t.Rows.Count - c & "条记录")
End If

 回到顶部