Introduction:
In this article i am going to explain about how to access the excel spreadsheet data using asp.net/c#.
Main:
using System.Data.OleDb;
string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\emp.xls; Extended Properties=Excel 8.0;";
string selectString = "SELECT * FROM [Sheet1$]";
OleDbConnection local_conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(selectString,local_conn);
local_conn.Open();
OleDbDataReader theData = cmd.ExecuteReader();
while (theData.Read())
{
Response.Write("{0}: {1} ({2}) – {3} ({4})", theData.GetString(0),theData.GetString(1),theData.GetString(2),theData.GetString(3),theData.GetString(4));
}
using System.Data.OleDb; string connectionString = "Provider=Microsoft.Jet.OleDb.4.0; data source=c:\\emp.xls; Extended Properties=Excel 8.0;"; string selectString = "SELECT * FROM [Sheet1$]"; OleDbConnection local_conn = new OleDbConnection(connectionString); OleDbCommand cmd = new OleDbCommand(selectString,local_conn); local_conn.Open(); OleDbDataReader theData = cmd.ExecuteReader(); while (theData.Read()) { Response.Write("{0}: {1} ({2}) – {3} ({4})", theData.GetString(0),theData.GetString(1),theData.GetString(2),theData.GetString(3),theData.GetString(4)); } |
Conclusion:
Hope this helps,
Happy Coding.