更新时间:2023-01-21 23:18:38
我想我已经找到解决方案,感谢Lamak的帮助:
I think I've found the solution, thanks to Lamak's help:
rst.Open sql, con
Dim iRows As Integer
For iCols = 0 To rst.Fields.Count - 1
ws.Cells(1, iCols + 1).Select
With Selection
.Value = rst.Fields(iCols).Name
.Font.Bold = True
.EntireColumn.AutoFit
End With
Next iCols
iRows = 2
While Not rst.EOF
For iCols = 0 To rst.Fields.Count - 1
ws.Cells(iRows, iCols + 1).Value = rst.Fields(iCols).Value
Next iCols
rst.MoveNext
iRows = iRows + 1
Wend
问题似乎一直在尝试将所有字段一次复制到记录集中,按字段和逐行复制记录字段似乎可以解决问题。
The problem seems to have been trying to copy all the fields out of the record set at once, copying the record field by field and row by row seems to solve the problem.