0

I would like to know how to import excel .xslsx I could do .xsls but no way to use xslsx if you could not answer just give me useful links

A81
  • 181
  • 2
  • 12
  • 1
    There are a lot of examples on the web, just search man. for ex: http://stackoverflow.com/questions/657131/how-to-read-data-of-an-excel-file-using-c and http://csharp.net-informations.com/excel/csharp-read-excel.htm. you must add a reference to the Microsoft Excel object library. Right click on your project and select Add Reference menu. After that go to COM tab and select and add Microsoft Excel 12.0 object library – AsfK Aug 30 '15 at 06:49

1 Answers1

1

i am using a function to import the excel sheet to a datatable and it's working with me

Please check it and tell me if you need anything

    public DataTable ImportExceltoDatatable(string filepath)
    {
        string sqlquery = "Select * From [Sheet1$]";
        DataSet ds = new DataSet();
        string constring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filepath + ";Extended Properties=\"Excel 12.0;HDR=YES;\"";
        OleDbConnection con = new OleDbConnection(constring + "");
        OleDbDataAdapter da = new OleDbDataAdapter(sqlquery, con);
        da.Fill(ds);
        DataTable dt = ds.Tables[0];
        return dt;
    }

this function will return a datatable that you can use in datagridview binding

Regards,

Ahmed Mandour
  • 330
  • 1
  • 8