Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. how can i bind data from excel file?

how can i bind data from excel file?

Scheduled Pinned Locked Moved Web Development
question
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    heinhtataung
    wrote on last edited by
    #1

    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:

    F 2 Replies Last reply
    0
    • H heinhtataung

      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:

      F Offline
      F Offline
      frostcox
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • H heinhtataung

        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:

        F Offline
        F Offline
        frostcox
        wrote on last edited by
        #3

        Another way is to save the excel file in csv(tab seperated) format and use a streamreader to read the file. Then declare an array and split the reader into the array, if you need a code sample let me know and il gladly provide it.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups