Foxtable(狐表)用户栏目专家坐堂 → 如何才能快速导入EXCEL数据


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

主题:如何才能快速导入EXCEL数据

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


加好友 发短信
等级:幼狐 帖子:166 积分:1946 威望:0 精华:0 注册:2012/12/26 15:47:00
如何才能快速导入EXCEL数据  发帖心情 Post By:2019/3/12 9:50:00 [显示全部帖子]

数据有15万行左右,
用下面的代码导入输入实在是太慢了,就像假死了一样,有没有快速一些的方法呢?

Dim v1 As WinForm.NumericComboBox = e.Form.Controls("NumericComboBox1")
Dim v2 As WinForm.NumericComboBox = e.Form.Controls("NumericComboBox2")
If v1.Value Is Nothing Then
    MessageBox.show("必须选择年份")
    Return
End If
If v2.Value Is Nothing Then
    MessageBox.show("必须选择月份")
    Return
End If
Dim t1 As Date = Date.Now

Dim tb As Table = Tables(e.Form.Name & "_table1")
Dim nt As Integer = v1.Value
Dim y As Integer = v2.Value

Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog,就是打开
dlg.Filter= "Excel| *.xls;*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim book As new XLS.Book(dlg.FileName)
    Dim sheet As XLS.Sheet = book.Sheets(0)  '第一个表
    Dim bar As WinForm.ProgressBar = e.Form.Controls("ProgressBar1")
    bar.Minimum= 0
    bar.Maximum =sheet.Rows.Count
    Dim nma() As String = {"catd","catz","catx","hotkeyword","keyfen","szkey","total","mobile","web","jz","ppc","click","roas"}
    DataTables("ST11Keyword").StopRedraw()
    tb.StopRedraw()
    For n As Integer = 3 To sheet.Rows.Count - 1
        Dim v As Integer = v + 1
        bar.Value = v
        Dim dr As DataRow = DataTables("ST11Keyword").AddNew()
        For i As Integer = 0 To sheet.Cols.Count - 1
            dr(nma(i)) = Sheet(n,i).Value
        Next
        dr("年") = nt
        dr("月") = y
    Next
    DataTables("ST11Keyword").Save
    DataTables("ST11Keyword").LoadFilter = "_identify = 0"
    DataTables("ST11Keyword").Load
    DataTables("ST11Keyword").ResumeRedraw()
    tb.ResumeRedraw()
    msgbox("ok")
End If
MessageBox.Show("计算结束, 耗时: " & (Date.Now - t1).TotalSeconds & "秒")

 回到顶部
帅哥哟,离线,有人找我吗?
zenbu
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:166 积分:1946 威望:0 精华:0 注册:2012/12/26 15:47:00
  发帖心情 Post By:2019/3/12 9:58:00 [显示全部帖子]

有好的办法吗?

 回到顶部