Foxtable(狐表)用户栏目专家坐堂 → Fox的EXCEL报表编程语法和VBA语法效率为何相差这么大?


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

主题:Fox的EXCEL报表编程语法和VBA语法效率为何相差这么大?

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


加好友 发短信
等级:八尾狐 帖子:1812 积分:12999 威望:0 精华:14 注册:2008/10/11 18:07:00
Fox的EXCEL报表编程语法和VBA语法效率为何相差这么大?  发帖心情 Post By:2012/5/19 6:45:00 [显示全部帖子]

往指定EXCEL文件的一行(15列)赋值,结果发现,方法二的效率高几倍!
想来方法二采用区域数组赋值是效率高的主要原因吗?

顺带请教:还有其它方法给Excel赋值吗?如SQL


方法一:Fox的EXCEL报表编程语法
Dim t1 As Date = Date.Now
Sn22 = drn22("內容")
sts= "2012@05@18@Rental@Cash@@OLY-1138@F019@@01 Jul 12 to 31 Jul 12@OS-02954@488@ABC@"
Dim Names As New List(Of String)
Names.AddRange(sts.split("@"))
Dim Book As New XLS.Book(T22)
Dim Sheet As XLS.Sheet = Book.Sheets(0)
For i As Integer = 0 To Names.Count - 1
    Sheet(Sn22-1, i).Value = Names(i) 
Next
Sheet(Sn22-1, 12).Value = val(Names(12))
Book.Save(T22) '保存工作簿
Output.Show("计算结束, 耗时: " & (Date.Now - t1).TotalSeconds & "秒")
'最快3秒(极少),最慢11秒(常常)


方法二:VBA语法

Dim t1 As Date = Date.Now
sts= "2012@05@18@Rental@Cash@@OLY-1138@F019@@01 Jul 12 to 31 Jul 12@OS-02954@488@ABC@"
Sn22 = drn22("內容")
Ap01 = New MSExcel.Application
Wb01 = Ap01.WorkBooks.Open(T22)
Ws01 = Wb01.WorkSheets(1)
Lsn1 = New List(of String)
If  sts IsNot Nothing Then
    sht = "A" & Sn22 & ":O" & Sn22
    Ary01  = sts.split("@")   '定义数组
    Rg01 = Ws01.Range(sht)
    Rg01.Value = Ary01 '写入指定的单元格
    Rg01 = Ws01.Range("M" & Sn22)
    Rg01.Value = Val(Ary01(Ary01.Length-3))
End If

wb01.save
Ap01.Quit
Output.Show("计算结束, 耗时: " & (Date.Now - t1).TotalSeconds & "秒")
'最快1.2秒,最慢3.5秒



 回到顶部