将单元格写入Excel的最快方法 [英] Fastest way to write cells to Excel

查看:210
本文介绍了将单元格写入Excel的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 调用consultaPlanilha()函数将数据从gridview导出到Excel。 )
Dim i,j As Integer'CONTADORES
ReDim vetPontos(GridPontos.Rows.Count - 2,1)


For i = 0 To GridPontos.Rows .Count - 2
For j = 0 To 1
vetPontos(i,j)= CDbl(GridPontos.Item(j,i).Value)
xlw.Application.Cells(i + 3,j + 2).Value = vetPontos(i,j)
下一个
下一个

xlw.Save()

大量数据需要很长时间。有没有更快的方法来一次写入大量的数据到Excel?

解决方案

你知道你可以做到这一点:

  Dim vetPontos()as Variant 
ReDim vetPontos(1 to 100,1 to 20)

For i = 1 to 100
对于j = 1到20
//填写vetPontos(i,j)
下一个j
下一个我

范围(A1)。 Resize(100,20).Value = vetPontos


I am writing a function to export data from a gridview to Excel this method on VB .NET:

     Call consultaPlanilha()
    Dim i, j As Integer  'CONTADORES
    ReDim vetPontos(GridPontos.Rows.Count - 2, 1)


    For i = 0 To GridPontos.Rows.Count - 2
        For j = 0 To 1
            vetPontos(i, j) = CDbl(GridPontos.Item(j, i).Value)
            xlw.Application.Cells(i + 3, j + 2).Value = vetPontos(i, j)
        Next
    Next

    xlw.Save()

This is taking a long time for large amounts of data. Is there a faster way to write a lot of data to Excel at once? Would doing something with ranges be faster?

解决方案

You know you can do this:

Dim vetPontos() as Variant
ReDim vetPontos(1 to 100, 1 to 20)

For i=1 to 100
  For j=1 to 20
   // fill in vetPontos(i,j)
  Next j
Next i

Range("A1").Resize(100,20).Value = vetPontos

这篇关于将单元格写入Excel的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆