Reading Excel sheet using ACE.OLEDB.12.0 with IMEX=1 not working

拥有回忆 提交于 2019-11-30 15:22:17

IMEX=1 does not return all data as text. It's a very common misconception.

What OLEDB does is scan the first n rows (default=8) and determines a data type. If you leave out the IMEX=1 then it will return Null for any values that do not match that data type. If you include IMEX=1 and the scan encounters mixed data types then it will return text. If your sheet has a text header then you can help this process by specifying HDR=No and discarding the header. However OLEDB will always scan the first n rows to determine the data type and return results accordingly.

The Rows to scan is determined by the value of TypeGuessRows.

The older Microsoft.Jet.OLEDB.4.0 driver would allow you to specify TypeGuessRows in the connection string but Microsoft.ACE.OLEDB.12.0 does not. TypeGuessRows is now held in the registry under...

Excel 2007: HKEY_LOCAL_MACHINE\Software\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows
Excel 2010: HKEY_LOCAL_MACHINE\Software\Microsoft\Office\14.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows
Excel 2013: HKEY_LOCAL_MACHINE\Software\Microsoft\Office\15.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows

32 Bit applications running on a 64 Bit Machine will find them under the Wow6432Node. E.g...

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows

This is a retrograde step in my opinion but I there must be a valid reason. If you find one let us know.

What worked for me, was to set IMEX=0 in the connection string. I have a SELECT and an UPDATE statement and just the SELECT statement was working when IMEX=1. Now both are working when IMEX=0

<add name="ExcleConn" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\ServerPath\Folder\GroupScheduling.xlsm;
     Extended Properties='Excel 12.0 Macro;HDR=YES;IMEX=0;Persist Security Info=False;ReadOnly=0;'"/>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!