Friday, September 23, 2011

Importing Excel with OleDbDataReader: handle cells with text length > 255

Most developers are familiar with importing excel sheets with OleDbDataReader. But not many know that Excel-OleDbDataReader cannot handle cells with text longer than 255 characters. This happens due to an intended behaviour in Excel.


When importing an excel sheet with the OleDBDataReader, it uses a registry setting called TypeGuessRows  to decide how many rows to inspect to guess the type of a column. Usually this setting is 8 rows. 


By changing that setting to zero forces Excel to check all the record to determine the column type:




The path to the registry key:







Remember:
1. You need to change the registry setting in correct Excel version ( e.g. 8.0, 12.0 etc).
2. If you are in a 64 bit machine, remember this Wow4232Node in the path.






No comments: