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. General Programming
  3. C#
  4. System.Data.OleDb & Microsoft Excel [modified]

System.Data.OleDb & Microsoft Excel [modified]

Scheduled Pinned Locked Moved C#
databasequestioncsharpcollaborationhelp
2 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.
  • S Offline
    S Offline
    shopi30
    wrote on last edited by
    #1

    Hello Code Project Team. Someone know how get the row index from excel spreadsheet? Example: [Profile.xls - spreadsheet1$]    | FirstName | LastName    | Age | ---|-----------|-------------|-----|  1 | Anthony   | Acuña       |  22 |  2 | Michael   | Danagan     |  24 |  3 | Benjamin  | Beat        |  24 |  4 | Monica    | Danagan     |  23 | C# Code OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Profile.xls;Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;MaxScanRows=0;\""; conn.Open(); DataTable dt = new DataTable(); string SQL = "SELECT * FROM [spreadsheet1$] WHERE FirstName LIKE 'M%'"; OleDbDataAdapter da = new OleDbDataAdapter(SQL, conn); da.Fill(dt); this.dataGridView1.SuspendLayout(); this.dataGridView1.DataSource = dt; this.dataGridView1.ResumeLayout(); This work correctly and only show: | FirstName | LastName    | Age | |-----------|-------------|-----| | Michael   | Danagan     |  24 | | Monica    | Danagan     |  23 | But I need retrieve what is the row index on excel file for every row. I need show the info in DataGridView in the follow format: | ExcelIndex | FirstName | LastName    | Age | |------------|-----------|-------------|-----| |          2 | Michael   | Danagan     |  24 | |          4 | Monica    | Danagan     |  23 | I hope that you can help me. Thanks in advanced. -- modified at 22:55 Sunday 12th November, 2006

    SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

    A 1 Reply Last reply
    0
    • S shopi30

      Hello Code Project Team. Someone know how get the row index from excel spreadsheet? Example: [Profile.xls - spreadsheet1$]    | FirstName | LastName    | Age | ---|-----------|-------------|-----|  1 | Anthony   | Acuña       |  22 |  2 | Michael   | Danagan     |  24 |  3 | Benjamin  | Beat        |  24 |  4 | Monica    | Danagan     |  23 | C# Code OleDbConnection conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Profile.xls;Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1;MaxScanRows=0;\""; conn.Open(); DataTable dt = new DataTable(); string SQL = "SELECT * FROM [spreadsheet1$] WHERE FirstName LIKE 'M%'"; OleDbDataAdapter da = new OleDbDataAdapter(SQL, conn); da.Fill(dt); this.dataGridView1.SuspendLayout(); this.dataGridView1.DataSource = dt; this.dataGridView1.ResumeLayout(); This work correctly and only show: | FirstName | LastName    | Age | |-----------|-------------|-----| | Michael   | Danagan     |  24 | | Monica    | Danagan     |  23 | But I need retrieve what is the row index on excel file for every row. I need show the info in DataGridView in the follow format: | ExcelIndex | FirstName | LastName    | Age | |------------|-----------|-------------|-----| |          2 | Michael   | Danagan     |  24 | |          4 | Monica    | Danagan     |  23 | I hope that you can help me. Thanks in advanced. -- modified at 22:55 Sunday 12th November, 2006

      SINCERELY. ANTHONY ACUÑA PREFERED PHRASE: SOMEBODY TELL ME WHY IS MORE REAL WHEN I DREAM THAT I AM WAKE?

      A Offline
      A Offline
      Anthony Mushrow
      wrote on last edited by
      #2

      Im gonna guess that you cant just add a row to the excel sheet, and write the numbers in yourself? Hmm, perhaps, creating a temporary array to store all the data from the excel sheet, then you can use the index from that, but of course, if its a big document it would consume alot of memory.

      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