Fallowing util method allows to select data from excel to DataTable
public static DataTable ReadFromExcel(string fileName)
{
DataTable dt = new DataTable();
try
{
OleDbConnection con = new OleDbConnection(string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0", fileName));
OleDbDataAdapter da = new OleDbDataAdapter("select * from list", con);
da.Fill(dt);
}
catch (Exception ex)
{
if (ex.Message.Contains("list"))
{
throw new ExcelRangeException();
}
else
{
throw ex;
}
}
return dt;
}
select * from list, where list is a range in excel
Monday, August 3, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment