Dim xl As New Excel.Application 'always use a variable to reference Excel, otherwise it may stay in memory, hidden.'
Dim b As Excel.Workbook = xl.Workbooks.Add 'do not use b = New Excel.Workbook, as this can cause a memory leak'
Dim s As Excel.Worksheet
xl.Visible = True
Dim sLast As Excel.Worksheet = b.Worksheets(b.Worksheets.Count)
b.Worksheets.Add(, sLast)
s = b.Worksheets(1) '1-based'
Dim o(199999, 1) As Object
For i As Integer = 0 To 199999
o(i, 0) = i.ToString
o(i, 1) = (200000 - i).ToString
Next i
s.Name = "ExcelDemo"
Dim r As Excel.Range = s.Range("A1", "B200000")
r.Value2 = o
s.Activate()
Dim strFilename As String = My.Computer.FileSystem.SpecialDirectories.Desktop & "\Junk" 'N.B. extension automatically added'
b.SaveAs(strFilename)
strFilename = b.FullName 'get full filename'
xl.Quit()
MsgBox(strFilename & " saved")
1 回答
我认为CSV是最快的,但
Excel.Range.Value2
允许您发送一个数组,而不是一次填充一个单元格: