以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 导入excel优化 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=147619) |
||||
-- 作者:fendouww -- 发布时间:2020/3/20 15:19:00 -- 导入excel优化 求老师帮助优化导入化码,目前导入没有问题,就是太慢,导入6条要60秒左右,有没有更好的代码写法?
|
||||
-- 作者:有点蓝 -- 发布时间:2020/3/20 15:47:00 -- 快不了多少了,每一行都要查询数据库,还要保存图片到共享目录里。 …… Dim Book As New XLS.Book(dlg.FileName) Dim Sheet As XLS.Sheet = Book.Sheets(0) Dim dict As new Dictionary(of String,Integer) For iii As Integer = 0 To sheet.Cols.Count -1 dict.Add(sheet(0,iii).Text,iii) Next Dim bh As Date Dim bj As String Dim ba As String Dim bi As String Dim bl As String Dim bx As String For n As Integer = 1 To Sheet.Rows.Count -1 bh = sheet(n,dict("下单时间")).Value bj = sheet(n,dict("长款号")).Text ba = sheet(n,dict("淘宝")).Text bi = sheet(n,dict("唯品会")).Text bl = sheet(n,dict("第三方")).Text bx = sheet(n,dict("汇总")).Text \'Dim bk As String = sheet(n,146).Text \' If bk > "" Then Dim Filter As String = "下单时间 = \'" & bh & "\' and 长款号 = \'" & bj & "\'" If ba > "" Then filter = Filter & " And " & "淘宝 = \'" & ba & "\'" End If If bi > "" Then filter = Filter & " And " & "唯品会 = \'" & bi & "\'" End If If bl > "" Then filter = Filter & " And " & "第三方 = \'" & bl & "\'" End If If bx > "" Then filter = Filter & " And " & "汇总 = \'" & bx & "\'" End If DataTables("下单表").AppendLoad(Filter,False) r = DataTables("下单表").Find(Filter) If r IsNot Nothing Then For i As Integer = 0 To sheet.Cols.Count -1 For Each m As String In nms Dim cname As String = sheet(0, i).Value If cname >"" AndAlso cname = m Then If Sheet(n,i).text > "" Then r(m) = Sheet(n,i).Value End If End If If cname = "图片" Then Dim fl As String = "\\\\10.100.100.129\\产品中心\\foxtable资料\\图片\\" & r("长款号") & ".jpg" If Sheet(n,i).SaveImage(fl) Then \'如果照片保存成功 r("图片") = fileSys.GetName(fl) End If End If Next Next Else r = DataTables("下单表").AddNew() …… |
||||
-- 作者:fendouww -- 发布时间:2020/3/21 8:55:00 -- 老师,谢谢,有办法不查询后台吗? |
||||
-- 作者:y2287958 -- 发布时间:2020/3/21 9:03:00 -- 上例子试试 |
||||
-- 作者:有点蓝 -- 发布时间:2020/3/21 10:05:00 -- 把表格数据都加载出来就不需要查询后台了。 当然要看数据量的多少,如果数据太多,几十上百万行,全部加载也是不现实的。如果经常需要这样导入数据的,可以做个服务端项目放到服务器运行,专门用来导入数据
|