how can i bind data from excel file?
-
I have the excel file (Insert.xls) and i want to bind the data from it. I wanna bind data with various Textboxes for each excel column. How can i read it ? please suggest me or please pay the sample codes for it. :(( :doh:
-
I have the excel file (Insert.xls) and i want to bind the data from it. I wanna bind data with various Textboxes for each excel column. How can i read it ? please suggest me or please pay the sample codes for it. :(( :doh:
Hey they are 2 ways which you can achieve this. You can get the cell range and store it in an array and then read the values from the array like so : this.openFileDialog1.FileName = "*.xls"; if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open( openFileDialog1.FileName, 0, true, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", false, false, 0, true); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1); for (int i = 1; i <= 10; i++) { Excel.Range range = worksheet.get_Range("A"+i.ToString(), "J" + i.ToString()); System.Array myvalues = (System.Array)range.Cells.Value; string[] strArray = ConvertToStringArray(myvalues); TextBox.Text = strArray[0].ToString(); } } or you could use OleDb like so assuming you have a sheet in the excel file called MyObject : 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); Hope this helps
-
I have the excel file (Insert.xls) and i want to bind the data from it. I wanna bind data with various Textboxes for each excel column. How can i read it ? please suggest me or please pay the sample codes for it. :(( :doh: