here is something that you can also try for starters mess around with it
if you need an example that uses Ranges..please let me know and I can post an example of that as well but this should be enough to get you started.
Change the code Sorce= to match your file path of the Excel file
using System.Data;
using System.Data.OleDb;
...
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=Excel 8.0");
OleDbDataAdapter da = new OleDbDataAdapter("select * from MyObject", con);
DataTable dt = new DataTable();
da.Fill(dt);
If you want a full example of how to read the excel file here is another example
Below is the whole code required for reading the Excel file.
void Read_My_Excel_File()
{
// Test.xls is in the C:\
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + C:\Test.xls + ";";
connectionString += "Extended Properties=Excel 8.0;";
// always read from the sheet1.
OleDbCommand myCommand = new OleDbCommand("Select * from [Sheet1$];");
OleDbConnection myConnection = new OleDbConnection(connectionString);
myConnection.Open();
myCommand.Connection = myConnection;
OleDbDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
// it can read upto 5 columns means A to E. In your case if the requirement is different then change the loop limits a/c to it.
for (int i = 0; i < 5; i++)
{
Response.Write(myReaderIdea.ToString() + " ");
}
Response.Write("<br>");
}
myConnection.Close();
}