Click here to Skip to main content
15,891,863 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys i have an excel file that has multiple column, i want to import the data from different column in the excel file and add the data to a collection list, any ideas what to do Please... Thanks
Posted

See here[^] for an article with a simple example.
 
Share this answer
 
you can try using this code. here a function write in C#. you put excel file name and sheet name then function return a datatable according your excel file data. also you can use this datatable any your purpose.

Code Here:
C#
public DataTable GetExcelSheetData(string excelFileName, string excelSheetNames)
    {
        OleDbConnection con = null;
        DataTable dt = new DataTable();
        String conStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
            "Data Source=" + excelFileName + ";Extended Properties=Excel 8.0;";
        con = new OleDbConnection(conStr);
        con.Open();
        OleDbCommand cmd = new OleDbCommand("select * from [" + excelSheetNames + "]", con);
        OleDbDataAdapter oleAdapter = new OleDbDataAdapter();
        oleAdapter.SelectCommand = cmd;
        oleAdapter.FillSchema(dt, SchemaType.Source);
        oleAdapter.Fill(dt);
        con.Close();
        return dt;
    }
 
Share this answer
 
A good starting point would be Ole connections. link below:
http://developers-heaven.net/forum/index.php/topic,45.0.html[^]
 
Share this answer
 
 
Share this answer
 
Comments
luisnike19 6-Jun-12 12:14pm    
Then go back with a good question

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900