Foxtable(狐表)用户栏目专家坐堂 → 导入报表


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

主题:导入报表

美女呀,离线,留言给我吧!
lss1988
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:9 积分:162 威望:0 精华:0 注册:2021/11/3 12:04:00
导入报表  发帖心情 Post By:2021/11/12 8:44:00 [只看该作者]

描述一:先导入EXCEL报表,内容有65000行,执行代码,结果可以运行
问题点:后运用文本文件导入数据,内容有73000行,执行代码,时间超过1个小时没有结果
请问:是行数超过65000行,运行不了么?

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


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/11/12 9:03:00 [只看该作者]

是文本文件导入数据慢,还是执行代码慢?文本文件正常导入了没?执行了什么代码?

 回到顶部
美女呀,离线,留言给我吧!
lss1988
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:9 积分:162 威望:0 精华:0 注册:2021/11/3 12:04:00
  发帖心情 Post By:2021/11/12 10:06:00 [只看该作者]


文本文件导入正常,
执行代码如下:

Dim d As Date= Date.Today

Dim y As new timespan(90, 0, 0, 0)

Dim e As new timespan(83, 0, 0, 0)

Dim f As new timespan(60, 0, 0, 0)

Dim g As new timespan(7, 0, 0, 0)

Dim h As new timespan(30, 0, 0, 0)

Dim s As Date 

s=d-y

Dim o As Date

o=d-e

Dim p As Date

P=d-f

Dim q As Date

Q=d-g

Dim r As Date

r=d-h

Dim dn As DataRow

For i As Integer=0 To DataTables("库存表20211005").datarows.count-1

dn=DataTables("库存表20211005").datarows(i)

dn("数量90天内")=DataTables("基础数据20211005").compute("sum(数量)", "[入库时间]>#" & s & "#  and  [物料编码]='"& dn("物料编码") &"'")

Next i

 

 

Dim dr As DataRow

Dim du As DataRow

Dim dv As DataRow

 

For j As Integer=0 To DataTables("库存表20211005").datarows.count-1

dr=DataTables("库存表20211005").datarows(j)

du=DataTables("库存表20210928").find("[物料编码]='"& dr("物料编码") &"'")

dv=DataTables("库存表20210907").find("[物料编码]='"& dr("物料编码") &"'")

 

If du Is Nothing

dr("与上周比90天内")=dr("数量90天内")

dr("本周到期转出90天内")=0

Else

dr("与上周比90天内")=dr("数量90天内")-du("数量90天内")

dr("本周到期转出90天内")=DataTables("基础数据20211005").compute("sum(数量)", "[入库时间]<#" & o & "#  and  [入库时间]>#" & s & "#  and  [物料编码]='"& dr("物料编码") &"'")

End If

 

If dv Is Nothing

dr("与上月比90天内")=dr("数量90天内")

dr("本月到期转出90天内")=0

Else

dr("与上月比90天内")=dr("数量90天内")-dv("数量90天内")

dr("本月到期转出90天内")=DataTables("基础数据20211005").compute("sum(数量)", "[入库时间]<#" & p & "#  and  [入库时间]>#" & s & "#  and  [物料编码]='"& dr("物料编码") &"'")

End If

 

dr("本周新近转入90天内")=DataTables("基础数据20211005").compute("sum(数量)", "[入库时间]>#" & q & "#   and  [物料编码]='"& dr("物料编码") &"'")

dr("本周库存消化库存报废退回库存90天内")=dr("与上周比90天内")+dr("本周到期转出90天内")-dr("本周新近转入90天内")

 

dr("本月新近转入90天内")=DataTables("基础数据20211005").compute("sum(数量)", "[入库时间]>#" & r & "#  and  [物料编码]='"& dr("物料编码") &"'")

dr("本月库存消化库存报废退回库存90天内")=dr("与上月比90天内")+dr("本月到期转出90天内")-dr("本月新近转入90天内")

Next j

 

Dim d2 As Date= Date.Today

Dim x2 As new timespan(91, 0, 0, 0)

Dim y2 As new timespan(180, 0, 0, 0)

Dim e2 As new timespan(173, 0, 0, 0)

Dim f2 As new timespan(150, 0, 0, 0)

Dim g2 As new timespan(98, 0, 0, 0)

Dim h2 As new timespan(121, 0, 0, 0)

Dim s2 As Date 

S2=d2-y2

Dim t2 As Date 

t2=d2-x2

Dim o2 As Date

O2=d2-e2

Dim p2 As Date

P2=d2-f2

Dim q2 As Date

Q2=d2-g2

Dim r2 As Date

R2=d2-h2

 

 

Dim dn2 as datarow

For i2 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dn2=DataTables("库存表20211005").datarows(i2)

dn2(数量91天至180天内)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & s2 & "#   and [入库时间]<=#" & t2 & "#  and  [物料编码]='"& dn2("物料编码") &"'")

Next i2

 

Dim dr2 As DataRow

Dim du2 As DataRow

Dim dv2 As DataRow

 

For j2 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dr2=DataTables("库存表20211005").datarows(j2)

du2=DataTables("库存表20210928").find("[物料编码]='"& dr2("物料编码") &"'")

dv2=DataTables("库存表20210907").find("[物料编码]='"& dr2("物料编码") &"'")

 

if du2 is nothing

dr2("与上周比91天至180天内")=dr2("数量91天至180天内")

dr2("本周到期转出91天至180天内")=0

else

dr2("与上周比91天至180天内")=dr2("数量91天至180天内")-du2("数量91天至180天内")

dr2("本周到期转出91天至180天内")=datatables(基础数据20211005).compute(sum(数量), [入库时间]<#" & o2 & "#  and  [入库时间]>#" & s2 & "#  and  [物料编码]='"& dr2("物料编码") &"'")

End if

 

if dv2 is nothing

dr2("与上91天至180天内")=dr2("数量91天至180天内")

dr2("本月到期转出91天至180天内")=0

else

dr2("与上91天至180天内")=dr2("数量91天至180天内")-dv2("数量91天至180天内")

dr2("本月到期转出91天至180天内")=datatables(基础数据20211005).compute(sum(数量), [入库时间]<#" & p2 & "#  and  [入库时间]>=#" & s2 & "#  and  [物料编码]='"& dr2("物料编码") &"'")

End if

 

dr2(“本周到期转入91天至180天内”)=datatables(“基础数据20211005”).compute(“sum(数量)”, “[入库时间]>#" &q2  & "#   and [入库时间]<=#" & t2 & "#  and  [物料编码]='"& dr2("物料编码") &"'")

dr2("本周库存消化库存报废退回库存91天至180天内")=dr2("与上周比91天至180天内")+dr2("本周到期转出91天至180天内")-dr2(“本周到期转入91天至180天内”)

 

dr2(本月到期转入91天至180天内)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & r2 & "#   and [入库时间]<=#" & t2 & "#  and  [物料编码]='"& dr2("物料编码") &"'")

dr2("库存消化库存报废退回库存91天至180天内")=dr2("与上91天至180天内")+dr2("本月到期转出91天至180天内")-dr2(本月到期转入91天至180天内)

 

Next j2

 

Dim d3 As Date= Date.Today

 

Dim x3 As new timespan(181, 0, 0, 0)

Dim y3 As new timespan(365, 0, 0, 0)

Dim e3 As new timespan(358, 0, 0, 0)

Dim f3 As new timespan(335, 0, 0, 0)

Dim g3 As new timespan(188, 0, 0, 0)

Dim h3 As new timespan(211, 0, 0, 0)

Dim s3 As Date 

S3=d3-y3

Dim t3 As Date 

T3=d3-x3

Dim o3 As Date

O3=d3-e3

Dim p3 As Date

P3=d3-f3

Dim q3 As Date

Q3=d3-g3

Dim r3 As Date

R3=d3-h3

 

 

 

Dim dn3 as datarow

For i3 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dn3=DataTables("库存表20211005").datarows(i3)

dn3(数量181天至365天内)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & s3 & "#   and [入库时间]<=#" & t3 & "#  and  [物料编码]='"& dn3("物料编码") &"'")

Next i3

 

Dim dr3 As DataRow

Dim du3 As DataRow

Dim dv3 As DataRow

 

For j3 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dr3=DataTables("库存表20211005").datarows(j3)

du3=DataTables("库存表20210928").find("[物料编码]='"& dr3("物料编码") &"'")

dv3=DataTables("库存表20210907").find("[物料编码]='"& dr3("物料编码") &"'")

 

if du3 is nothing

dr3("与上周比181天至365天内")=dr3("数量181天至365天内")

dr3("本周到期转出181天至365天内")=0

else

dr3("与上周比181天至365天内")=dr3("数量181天至365天内")-du3("数量181天至365天内")

dr3("本周到期转出181天至365天内")=datatables(基础数据20211005).compute(sum(数量), [入库时间]<#" & o3 & "#  and  [入库时间]>=#" & s3 & "#  and  [物料编码]='"& dr3("物料编码") &"'")

End if

 

if dv3 is nothing

dr3("与上181天至365天内")=dr3("数量181天至365天内")

dr3("本月到期转出181天至365天内")=0

else

dr3("与上181天至365天内")=dr3("数量181天至365天内")-dv3("数量181天至365天内")

dr3("本月到期转出181天至365天内")=datatables(基础数据20211005).compute(sum(数量), [入库时间]<#" & p3 & "#  and  [入库时间]>=#" & s3 & "#  and  [物料编码]='"& dr3("物料编码") &"'")

End if

 

dr3(“本周到期转入181天至365天内”)=datatables(“基础数据20211005”).compute(“sum(数量)”, “[入库时间]>#" & q3 & "#   and [入库时间]<=#" & t3 & "#  and  [物料编码]='"& dr3("物料编码") &"'")

dr3("本周库存消化库存报废退回库存181天至365天内")=dr3("与上周比181天至365天内")+dr3("本周到期转出181天至365天内")-dr3(“本周到期转入181天至365天内”)

 

dr3(本月到期转入181天至365天内)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & r3 & "#   and [入库时间]<=#" & t3 & "#  and  [物料编码]='"& dr3("物料编码") &"'")

dr3("库存消化库存报废退回库存181天至365天内")=dr3("与上181天至365天内")+dr3("本月到期转出181天至365天内")-dr3(本月到期转入181天至365天内)

 

Next j3

Dim d4 As Date= Date.Today

 

Dim x4 As new timespan(366, 0, 0, 0)

Dim y4 As new timespan(730, 0, 0, 0)

Dim e4 As new timespan(723, 0, 0, 0)

Dim f4 As new timespan(700, 0, 0, 0)

Dim g4 As new timespan(373, 0, 0, 0)

Dim h4 As new timespan(396, 0, 0, 0)

Dim s4 As Date 

这是基础数据,共有73000多行,按照物料编码的间隔日期数量汇总,如90天第一种物料编码汇总多少

这是想要表述出来的


 回到顶部
美女呀,离线,留言给我吧!
lss1988
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:9 积分:162 威望:0 精华:0 注册:2021/11/3 12:04:00
  发帖心情 Post By:2021/11/12 10:06:00 [只看该作者]

执行代码比较慢

 回到顶部
美女呀,离线,留言给我吧!
lss1988
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:9 积分:162 威望:0 精华:0 注册:2021/11/3 12:04:00
  发帖心情 Post By:2021/11/12 10:11:00 [只看该作者]

s4=d4-y4

Dim t4 As Date 

T4=d4-x4

Dim o4 As Date

o4=d4-e4

Dim p4 As Date

p4=d4-f4

Dim q4 As Date

q4=d4-g4

Dim r4 As Date

r4=d4-h4

 

 

 

Dim dn4 as datarow

For i4 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dn4=DataTables("库存表20211005").datarows(i4)

dn4(数量366天至730天内)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & s4 & "#   and [入库时间]<=#" & t4 & "#  and  [物料编码]='"& dn4("物料编码") &"'")

Next i4

 

Dim dr4 As DataRow

Dim du4 As DataRow

Dim dv4 As DataRow

 

For j4 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dr4=DataTables("库存表20211005").datarows(j4)

du4=DataTables("库存表20210928").find("[物料编码]='"& dr4("物料编码") &"'")

dv4=DataTables("库存表20210907").find("[物料编码]='"& dr4("物料编码") &"'")

 

if du4 is nothing

dr4("与上周比366天至730天内")=dr4("数量366天至730天内")

dr4("本周到期转出366天至730天内")=0

else

dr4("与上周比366天至730天内")=dr4("数量366天至730天内")-du4("数量366天至730天内")

dr4("本周到期转出366天至730天内")=datatables(基础数据20211005).compute(sum(数量), [入库时间]<#" & o4 & "#  and  [入库时间]>#" & s4 & "#  and  [物料编码]='"& dr4("物料编码") &"'")

End if

 

if dv4 is nothing

dr4("与上366天至730天内")=dr4("数量366天至730天内")

dr4("本月到期转出366天至730天内")=0

else

dr4("与上366天至730天内")=dr4("数量366天至730天内")-dv4("数量366天至730天内")

dr4("本月到期转出366天至730天内")=datatables(基础数据20211005).compute(sum(数量), [入库时间]<#" & p4 & "#  and  [入库时间]>#" & s4 & "#  and  [物料编码]='"& dr4("物料编码") &"'")

End if

 

dr4(“本周到期转入366天至730天内”)=datatables(“基础数据20211005”).compute(“sum(数量)”, “[入库时间]>#" & q4 & "#   and [入库时间]<=#" & t4 & "#  and  [物料编码]='"& dr4("物料编码") &"'")

dr4("本周库存消化库存报废退回库存366天至730天内")=dr4("与上周比366天至730天内")+dr4("本周到期转出366天至730天内")-dr4(“本周到期转入366天至730天内”)

 

dr4(本月到期转入366天至730天内)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & r4 & "#   and [入库时间]<=#" & t4 & "#  and  [物料编码]='"& dr4("物料编码") &"'")

dr4("库存消化库存报废退回库存366天至730天内")=dr4("与上366天至730天内")+dr4("本月到期转出366天至730天内")-dr4(本月到期转入366天至730天内)

 

Next j4

 

 

Dim d5 As Date= Date.Today

 

Dim x5 As new timespan(731, 0, 0, 0)

 

Dim e5 As new timespan(713, 0, 0, 0)

Dim f5 As new timespan(690, 0, 0, 0)

Dim g5 As new timespan(738, 0, 0, 0)

Dim h5 As new timespan(766, 0, 0, 0)

 

Dim t5 As Date 

T5=d5-x5

Dim o5 As Date

O5=d5-e5

Dim p5 As Date

P5=d5-f5

Dim q5 As Date

Q5=d5-g5

Dim r5 As Date

R5=d5-h5

 

 

Dim dn5 as datarow

For i5 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dn5=DataTables("库存表20211005").datarows(i5)

dn5(数量731天以外)=datatables(基础数据20211005).compute(sum(数量), [入库时间]<=#" & t5 & "#  and  [物料编码]='"& dn5("物料编码") &"'")

Next i5

 

Dim dr5 As DataRow

Dim du5 As DataRow

Dim dv5 As DataRow

 

For j5 As Integer=0 To DataTables("库存表20211005").datarows.count-1

dr5=DataTables("库存表20211005").datarows(j5)

du5=DataTables("库存表20210928").find("[物料编码]='"& dr5("物料编码") &"'")

dv5=DataTables("库存表20210907").find("[物料编码]='"& dr5("物料编码") &"'")

 

if du5 is nothing

dr5("与上周比731天以外")=dr5("数量731天以外")

dr5("本周到期转出731天以外")=0

else

dr5("与上周比731天以外")=dr5("数量731天以外")-du5("数量731天以外")

dr5("本周到期转出731天以外")=0

End if

 

if dv5 is nothing

dr5("与上731天以外")=dr5("数量731天以外")

dr5("本月到期转出731天以外")=0

else

dr5("与上731天以外")=dr5("数量731天以外")-dv5("数量731天以外")

dr5("本月到期转出731天以外")=0

End if

 

dr5(“本周到期转入731天以外”)=datatables(“基础数据20211005”).compute(“sum(数量)”, “[入库时间]>#" & q5 & "#   and [入库时间]<=#" & t5 & "#  and  [物料编码]='"& dr5("物料编码") &"'")

dr5("本周库存消化库存报废退回库存731天以外")=dr5("与上周比731天以外")+dr5("本周到期转出731天以外")-dr5(“本周到期转入731天以外”)

 

dr5(本月到期转入731天以外)=datatables(基础数据20211005).compute(sum(数量), [入库时间]>#" & r5 & "#   and [入库时间]<=#" & t5 & "#  and  [物料编码]='"& dr5("物料编码") &"'")

dr5("库存消化库存报废退回库存731天以外")=dr5("与上731天以外")+dr5("本月到期转出731天以外")-dr5(本月到期转入731天以外)


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


加好友 发短信
等级:超级版主 帖子:106209 积分:540168 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/11/12 10:56:00 [只看该作者]

这种计算方法肯定慢了,行数越多就越慢。

优化方法
1、不要每个计算就遍历所有行一次,放到一个for循环里对各种功能进行计算就行了
下面是2个循环
For i As Integer=0 To DataTables("库存表20211005").datarows.count-1
循环1的代码
Next 
Dim dr As DataRow
Dim du As DataRow
Dim dv As DataRow
For j As Integer=0 To DataTables("库存表20211005").datarows.count-1
循环2的代码
Next 

完全可以放到一个循环里做
For i As Integer=0 To DataTables("库存表20211005").datarows.count-1
循环1的代码
Dim dr As DataRow
Dim du As DataRow
Dim dv As DataRow
循环2的代码
Next 

所有的循环都可以合并为一个。这样表格有72000行,只需要循环72000次,原来的用法10个功能循环10次,也就是需要循环72000 * 10 = 720000次

2、看大部分计算方法都是从历史表里查询然后计算,这种建议使用SQLGroupTableBuilder进行多表关联统计:http://www.foxtable.com/webhelp/topics/1626.htm

 回到顶部
美女呀,离线,留言给我吧!
lss1988
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:婴狐 帖子:9 积分:162 威望:0 精华:0 注册:2021/11/3 12:04:00
  发帖心情 Post By:2021/11/12 14:23:00 [只看该作者]

谢谢蓝老师

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


加好友 发短信
等级:一尾狐 帖子:437 积分:3749 威望:0 精华:0 注册:2016/10/14 13:40:00
  发帖心情 Post By:2021/11/14 23:32:00 [只看该作者]


 回到顶部