Paso 1: Descargar el setup de Access Database Engine 2010 Redistributable
http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=13255
Paso 2: Ocupar “Microsoft Excel Driver” con las clases de Odbc indicando la ruta del archivo.
Importamos la libreria System.Data.Odbc
Código:
string CadenaConexion = @"driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};driverid=1046;dbq=C:\Users\v-edisga\Desktop\Libro1.xlsx;";
DataSet ds = null;
try
{
using (OdbcConnection conn = new OdbcConnection(CadenaConexion))
{
conn.Open();
using (OdbcCommand command = conn.CreateCommand())
{
command.CommandText = "SELECT * FROM [Hoja1$]";
OdbcDataAdapter ad = new OdbcDataAdapter(command);
ds = new DataSet();
ad.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
Source: http://ewebmx.com/2011/08/como-leer-un-archivo-de-excel-2010-en-c/