Nice to see this Question it's easy as I have recently accomplished project on Excel Worksheet.
Take my Work.
You could probably use
OleDbProvider
to meet to your requirement rather the using
Interop
COM Componant.
Here the Code Goes.
protected void btnUpload_Click(object sender, EventArgs e)
{
OleDbConnection objConnection = new OleDbConnection(ConnectionString());
objConnection.Open();
OleDbCommand objCmdSelect = new OleDbCommand("SELECT * FROM [" + SheetName + "$]", objConnection);
OleDbDataAdapter objAdapter = new OleDbDataAdapter(objCmdSelect);
DataTable Dt = new DataTable();
objAdapter.Fill(Dt);
objConnection.Close();
}
private String ConnectionString()
{
return @"Provider=Microsoft.Jet.OLEDB.4.0;" +
@"Data Source=" + fupdControl.PostedFile.FileName + ";" +
@"Extended Properties=Excel 8.0;";
}
Here input the
SheetName
and
ExcelFileLocation
it will retrieve all the data of that sheet into datatable, the column name of the datatable will be the column name of the Sheet.
http://www.codeguru.com/forum/archive/index.php/t-388883.html[
^]
Please
Vote or
Accept Answer if it Helped.