tags:

views:

172

answers:

3

ADO.NET just fails miserably when it's used to read Excel files where a column contains mixed data types. It appears that it tries to determine the data type of a column, and then assume the rest of the entire column is of the same data type. Here are some backgrounds:

http://stackoverflow.com/questions/2968111/how-to-prevent-ado-net-from-altering-double-values-when-it-reads-from-excel-files

http://blog.lab49.com/archives/196

What is an alternative approach that doesn't require automation, Excel to be co-installed, is simple (since the input excel file will only have one worksheet in each file).

+3  A: 

It depends a little on the Excel versions you need to support. I've used ExcelPackage successfully in the past for reading and creating Excel 2007 files. It is no longer under development, which is a bit of a shame. You'd have to manually loop though all the cells, which I wouldn't call elegant, but it's flexible ;)

Leniel has suggested using EPPlus over ExcelPackage. I haven't used it myself, but it looks very promising.

There are several other suggestions in this question, but I have no experience with the other libraries.

Thorarin
@Thorarin - ExcelPackage looks promising.
Khnle
@Khnle: After my answer, you added the **.xls** requirement. It doesn't do files older than Excel 2007 (.xslx), but some of these other libraries do.
Thorarin
I can add support for Aspose, indirectly mentioned in the linked question. It's expensive, but high quality. ( http://www.aspose.com/ )
ladenedge
http://epplus.codeplex.com/ surpasses ExcelPackage. Take a look at it if you plan to work with XLSX format.
Leniel Macaferi
@Leniel: looks very nice indeed...
Thorarin
A: 

You can read a XLS file with Myxls library, is free and open source, you can see an example in the this url: Myxls example

majimenezp
+2  A: 

I heart NPOI.

http://npoi.codeplex.com/

Jay