views:

65

answers:

1

I use OleDB to read an Excel file. One of the columns has a "Common" format and contains both strings with letters and values consisting of numbers only. String values are retrieved without problem, but pure numerical values are retrieved as DBNull.

How to solve?

I use the following connection string to open Excel 2003 file (xls):

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\file.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\""
+1  A: 

I found some documentation on Microsoft's website that applies to your scenario. They recommend converting all the numerics to strings.

http://support.microsoft.com/kb/257819

As stated previously, ADO must guess at the data type for each column in your Excel worksheet or range. (This is not affected by Excel cell formatting settings.) A serious problem can arise if you have numeric values mixed with text values in the same column. Both the Jet and the ODBC Provider return the data of the majority type, but return NULL (empty) values for the minority data type. If the two types are equally mixed in the column, the provider chooses numeric over text.

For example:

* In your eight (8) scanned rows, if the column contains five (5) numeric values and three (3) text values, the provider returns five (5) numbers and three (3) null values.
* In your eight (8) scanned rows, if the column contains three (3) numeric values and five (5) text values, the provider returns three (3) null values and five (5) text values.
* In your eight (8) scanned rows, if the column contains four (4) numeric values and four (4) text values, the provider returns four (4) numbers and four (4) null values.
jdot
I added `IMEX=1` to enforce text mode (I need to retrieve this cells as text not numeric) but it didn't help.It's impossible to reenter values in text mode because there are to many of them. Is it possible to automate it somehow?
flashnik
What if you try this suggestion of using a query instead of direct table/sheet name? Slight drawback is that all columns come across as strings then.http://munishbansal.wordpress.com/2009/12/15/importing-data-from-excel-having-mixed-data-types-in-a-column-ssis/
jdot