往指定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秒(常常)
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秒