问题
I am connecting to xlsx files via ODBC with following command:
"DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb);HDR=YES;IMEX=1;READONLY=TRUE;DBQ=C:\Temp\test.xlsx"
It works fine but I am always missing one line when there is no header in the file. Obviously it's because of the parameter "HDR=YES" but I cant figure out how to disable the header line.
I have tried "HDR=NO" and leaving this parameter out but no effect. I can access to the file but I always lose the first line.
Can somebody help me with that?
Thanks!
回答1:
I did some research.
If you open a XLS or XLSX file via a driver like
"DRIVER=Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb);HDR=YES;IMEX=1;READONLY=TRUE;DBQ=C:\Temp\test.xlsx"
the driver is ignoring parameters completly. So "HDR=NO" has no effect.
Apparently the driver uses a setting in the registry to determine if the first line should be interpreted as an header line.
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\Access Connectivity Engine\Engines\Excel
So if you set FirstRowHasNames=00 the first line wont be skipped.
Source
来源:https://stackoverflow.com/questions/49506048/odbc-xlsx-driver-connectionstring-without-header