Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
844 views
in Technique[技术] by (71.8m points)

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

I'm using the below Connection String with ACE.OLEDB.12.0 to read data from an XLSX Spreadsheet, but the I set IMEX=1, it does not work while when I remove IMEX=1 completely, it works fine.

"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:Working FolderICDERamsden 4.xlsx;Extended Properties=""Excel 12.0 xml;HDR=No;IMEX=1;"""

Can anyone explain why? Because I had the impression that IMEX=1 reads all data as text, so it was more secure!

Thanks

JP

IMEX= <0/1/2> IMEX refers to IMport EXport mode. This can take three possible values.

IMEX=0 and IMEX=2 will result in ImportMixedTypes being ignored and the default value of ‘Majority Types’ is used. In this case, it will take the first 8 rows and then the data type for each column will be decided.

IMEX=1 is the only way to set the value of ImportMixedTypes as Text. Here, everything will be treated as text.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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_MACHINESoftwareMicrosoftOffice12.0Access Connectivity EngineEnginesExcelTypeGuessRows
Excel 2010: HKEY_LOCAL_MACHINESoftwareMicrosoftOffice14.0Access Connectivity EngineEnginesExcelTypeGuessRows
Excel 2013: HKEY_LOCAL_MACHINESoftwareMicrosoftOffice15.0Access Connectivity EngineEnginesExcelTypeGuessRows

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

HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftOffice12.0Access Connectivity EngineEnginesExcelTypeGuessRows

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...