问题
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.
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
回答1:
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.)
来源:https://stackoverflow.com/questions/36568793/adodb-recordset-column-headers