问题描述
我正在将 ADODB.Recordset
数据复制到excel文件中,但是它将记录集数据复制到没有列标题的excel中。我正在使用MS Access 2013, CompyFromRecordset
命令。
I'm copying ADODB.Recordset
data to excel file, but it copies the recordset data to excel without column headers.I'm using MS Access 2013, CompyFromRecordset
command.
我的问题是,有没有办法复制RecordSet的数据头?
my question is, is there any way to copy the data headers of RecordSet?
For i = 0 To iFieldCount - 1
objSheet.Range("A" & i + 1).CopyFromRecordset rst
objBook.Save
Next i
推荐答案
A 标题不是记录,并且 CopyFromRecordset
命令不包含标题。
A "header" is not a record and the CopyFromRecordset
command does not include the headers.
您必须放置标题通过遍历返回的记录集的字段名自己在工作表中,例如:
You must put the header in your sheet yourself by iterating over the fieldnames of the returned recordset, something like:
For i = 1 To iFieldCount
objSheet.Range("A" & i) = rst.Field(i).Name
Next i
(注意:我没有测试代码;可能有一些错误。)
(Note: I didn't test the code; there may be some errors.)
这篇关于ADODB记录集列标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!