参考下面数组的输出方式,效率快很多
Dim xlApp As New MSExcel.Application
'xlApp.Visible = True
xlapp.ScreenUpdating = False
Dim wbNew As MSExcel.Workbook
Dim wsNew As MSExcel.WorkSheet
Dim rng As MSExcel.range
’try
For Each strPLID As String In lstPLID
ws.copy
(after:= wbNew.worksheets(wbnew.worksheets.count)) 'Copy 模板
wsNew =
xlApp.activeworkbook.activesheet '获取当前Copy模板 ,这两行好像可以合并一行
Dim n As Integer ' 定义你要输出的行数
If n = 0 Then Continue For
Dim arr(0 To n - 1,0 To 5) '定义个数组
For IntA = 0 To n - 1
Dim dr As DataRow = lstdr(IntA)
arr(IntA,0) =
arr(IntA,1) =
arr(IntA,2) =
arr(IntA,3) =
arr(IntA,4) =
arr(IntA,5) =
Next
wsNew.range("A15").resize(n,ubound(arr,2) + 1).value = arr '比你一行行块10-100倍,行数越多效率越高
Next
xlapp.DisplayAlerts = False
Dim str As String = '保存的文件名
wbNew.worksheets(1).delete
wbNew.saveas(strFileGen & str)
wb.close
xlapp.DisplayAlerts = True
xlapp.ScreenUpdating = True
xlapp.visible = True
[此贴子已经被作者于2014-1-23 17:05:11编辑过]