Last post Jan 30, 2010 03:55 PM by tosho
Jan 30, 2010 01:18 PM|Tosho|LINK
Hi ASP.net experts,
I have some numerical data in an EXcel sheet. I need to get that data and process in my aspx page. I tried to understand by googling how to fetch an entry from Excel into a variable (Lable for example) in my aspx page but
was not successful. If you can please point me to simple example or let my know how to code it, it would really appriciate it. Please note my knowledge in databases is almost nill.
Jan 30, 2010 01:37 PM|SGWellens|LINK
This may help:
// using System.Data.OleDb
OleDbConnection ExcelConection = null;
OleDbCommand ExcelCommand = null;
OleDbDataReader ExcelReader = null;
OleDbConnectionStringBuilder OleStringBuilder = null;
new OleDbConnectionStringBuilder(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyExcel.xls;Extended Properties='Excel 8.0;HDR=Yes;IMEX=1';");
OleStringBuilder.DataSource = MapPath(@"~\App_Datav\MyExcelWorksheet.xls");
ExcelConection = new OleDbConnection();
ExcelConection.ConnectionString = OleStringBuilder.ConnectionString;
ExcelCommand = new OleDbCommand();
ExcelCommand.Connection = ExcelConection;
ExcelCommand.CommandText = "Select * From [Sheet1$]";
ExcelReader = ExcelCommand.ExecuteReader();
GridView1.DataSource = ExcelReader;
catch (Exception Args)
LabelErrorMsg.Text = "Could not open Excel file: " + Args.Message;
if (ExcelCommand != null)
if (ExcelReader != null)
if (ExcelConection != null)
Jan 30, 2010 03:55 PM|Tosho|LINK
Thank you very much Steve.
The code worked fine, it brought my Excel sheet to ASP.net page that I could see on the client page (web browser). Could you please advise me how I can address elements in the sheet. I need to pull the numbers from the sheet and process them. For example,in
Excel, the addresses are A1, A2, D5, E7 etc.
I would really appreciate if you could please give me an example with reference to your advised code in your earlier post, it shall get me going.