克隆现有logging集以优化logging集

我有一个logging集,其中包含需要导入到Excel文件中的所有数据。 有没有一种方法可以将我的实时logging集复制到打开Excel文件时创build的logging集中?

这是我正在尝试没有运气。

Dim connection : Set connection = Server.CreateObject("ADODB.Connection") connection.Open "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=c:\MyExcel.xls;" & _ "DefaultDir=c:\; ReadOnly=False;" Dim excelRecordset : Set excelRecordset = Server.CreateObject("ADODB.Recordset") excelRecordset.Open "[SHEET1$]", connection, 2, 3 excelRecordset.AddNew Set excelRecordset = recordset.clone excelRecordset.Update excelRecordset.Close 

谢谢。

当你这样做:

 Set excelRecordset = recordset.clone 

您将引用replace为Excel电子表格中打开的logging集(并closures),并引用新的logging集。 这个新的logging集不会连接到Excel电子表格。

使用logging集,除了通过源logging集的AddNew For Each字段,从源到目的地和Update ,分配每个字段都没有多lessselect。

Excel Range对象有一个CopyFromRecordset方法应该做这个工作。 如果你可以创build一个Excel.Application对象并打开你想写的工作簿,那么你应该可以使用它。

因此,如果现有的logging集名为rs并且已经被填充,那么VBA中的代码将是:

 Worksheets("SHEET1").Cells(2, 1).CopyFromRecordset rs 

然后你可以迭代rs.Fields来填写字段名称

 Dim fld As Field Dim i As Integer i = 1 With Worksheets("SHEET1") For Each fld in rs.Fields .Cells(1, i).Value = fld.Name i = i + 1 Next fld End With 

不知道这将是多么容易转化为您的scheme。

或者,如果您正在使用的驱动程序可用,则可能需要查看此知识库文章中描述的SELECT INTOINSERT INTO语法