Saturday, 30 June 2012

Read Excel file in C#




protected void BtnReadExcel_Click(object sender, EventArgs e)
        {
            try
            {
              OleDbConnection con = new OleDbConnection("
                                                Provider=Microsoft.Jet.OLEDB.4.0;
                                                Data Source="
+ Server.MapPath("TestExcel.xlsx") + ";
                                                Extended Properties='Excel 8.0;HDR=Yes;'"
 

                                               );
                OleDbDataAdapter da = new OleDbDataAdapter("select * from [Sheet1$]",
                                                                                 con);
                DataSet ds = new DataSet();
                da.Fill(ds);
            }
            catch (Exception ex)
            {
                throw;
            }

        }

No comments:

Post a Comment