问题
I am using ADO to import data from Excel workbooks. I'm having some troubles with one worksheets where one column name contains a dot : "Col.1".
I tried everything I found : double quotes, brackets, backstick. Nothing works. Either an error is raised or the query output "Col.1" on every row.
QUERY_SQL = _
"SELECT `Col.1`, Col3 FROM [table$] " & _
"IN '" & SourcePath & "' " & CHAINE_HDR
Given the fact that I can't rename the column in the source file,
How can I manually select this column using its name not its number ([F1]) ?
回答1:
I finally found how to retrieve data from this column.
You need to replace "." by "#" and put the column name in square brackets or backsticks :
QUERY_SQL = _
"SELECT `Col#1`, Col3 FROM [table$] " & _
"IN '" & SourcePath & "' " & CHAINE_HDR
However this will not work in INSERT INTO queries. :
INSERT INTO [sheet$] (Col2, `Col#4`) IN '" & TargetPath & "' 'Excel 12.0;' " & QUERY_SQL
While this is less problematic for me as I can rename all field in the target sheets, this is still a strange behaviour.
来源:https://stackoverflow.com/questions/43784289/how-to-select-column-which-field-name-contains-a-dot