这段是VB将查询的结果显示在ListView里,然后再从ListView将数据导出到excel,感觉太慢了,导出500条记录就要花6秒左右,很慢,麻烦高手帮忙优化一下,谢谢了。
Set xlSheet = xlBook.Worksheets("sheet1") '设置活动工作表
For aa1 = 1 To ListView1.ListItems.Count
xlSheet.Cells(aa1 + 1, 1) = ListView1.ListItems(aa1).Text '给Excek单元格赋值
xlSheet.Cells(aa1 + 1, 2) = ListView1.ListItems(aa1).SubItems(1)
xlSheet.Cells(aa1 + 1, 3) = ListView1.ListItems(aa1).SubItems(2)
xlSheet.Cells(aa1 + 1, 4) = ListView1.ListItems(aa1).SubItems(3)
xlSheet.Cells(aa1 + 1, 5) = ListView1.ListItems(aa1).SubItems(4)
xlSheet.Cells(aa1 + 1, 6) = ListView1.ListItems(aa1).SubItems(5)
xlSheet.Cells(aa1 + 1, 7) = ListView1.ListItems(aa1).SubItems(6)
xlSheet.Cells(aa1 + 1, 8) = ListView1.ListItems(aa1).SubItems(7)
xlSheet.Cells(aa1 + 1, 9) = ListView1.ListItems(aa1).SubItems(8)
xlSheet.Cells(aa1 + 1, 10) = ListView1.ListItems(aa1).SubItems(9)
xlSheet.Cells(aa1 + 1, 11) = ListView1.ListItems(aa1).SubItems(10)
xlSheet.Cells(aa1 + 1, 12) = ListView1.ListItems(aa1).SubItems(11)
xlSheet.Cells(aa1 + 1, 13) = ListView1.ListItems(aa1).SubItems(12)
xlSheet.Cells(aa1 + 1, 14) = ListView1.ListItems(aa1).SubItems(13)
xlSheet.Cells(aa1 + 1, 14) = ListView1.ListItems(aa1).SubItems(14)
Next aa1
VB将数据导出excel太慢了,请帮忙优化代码,谢谢!
答案:2 悬赏:30 手机版
解决时间 2021-03-21 03:40
- 提问者网友:酱爆肉
- 2021-03-20 21:28
最佳答案
- 五星知识达人网友:玩家
- 2021-03-20 22:41
定义一个数组,把ListView写入数组中,将数组导出到Excel,1秒应该差不多。
xlSheet.Cells(2, 1).Resize(UBound(myAry, 1) + 1, UBound(myAry, 2) + 1) = myAry
xlSheet.Cells(2, 1).Resize(UBound(myAry, 1) + 1, UBound(myAry, 2) + 1) = myAry
全部回答
- 1楼网友:深街酒徒
- 2021-03-20 22:58
private sub commandbutton1_click()
workbooks.open filename:=thisworkbook.path & "\" & "abc.xls"
range("a65500").end(xlup).offset(1, 0) = me.textbox1
range("b65500").end(xlup).offset(1, 0) = me.textbox2
range("c65500").end(xlup).offset(1, 0) = me.textbox3
range("d65500").end(xlup).offset(1, 0) = me.textbox4
range("e65500").end(xlup).offset(1, 0) = me.textbox5
range("f65500").end(xlup).offset(1, 0) = me.textbox6
range("g65500").end(xlup).offset(1, 0) = me.textbox7
activeworkbook.close 1
end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯