none
import table from excel RRS feed

  • Question

  •  

    hello,

     

    i have an excel worksheet that contains a single table in it.

    how can i import this table to a datatable using c#?

    what's the best way to do it?

    i want the datatable's columns names to be equal to the excel table's columns' names

     

    is it possible??

     

    thanks

     

    Tuesday, December 25, 2007 6:28 PM

Answers

  • It is because Excel is not real database and columns do not have any specific data type. Jet OLEDB provider tries to detect type of columns based on initial scan of first N rows. For the cells that do not match detected type, Jet provider returns NULL values. You could use COM-based Excel library if you need to access data in native type. I also created my own Excel reader that returns data in native format, so you could try it from my web site.

    Thursday, December 27, 2007 8:22 PM
    Moderator

All replies

  • Ok, i can get the data now and the columns' names... but i have a problem:

    when i have columns in the excel sheet that dosn't all have the same type (int, string ...) the import makes alot of problems: columns' names not good and not all the data is imported...

     

    help...

    Tuesday, December 25, 2007 6:53 PM
  • It is because Excel is not real database and columns do not have any specific data type. Jet OLEDB provider tries to detect type of columns based on initial scan of first N rows. For the cells that do not match detected type, Jet provider returns NULL values. You could use COM-based Excel library if you need to access data in native type. I also created my own Excel reader that returns data in native format, so you could try it from my web site.

    Thursday, December 27, 2007 8:22 PM
    Moderator