Search code examples
c#exceloledb

How can I get A1 cell from a 97/03 Excel document with OleDB?


I've got a Excel 97/03 document that has "blabla" in its A1 cell in sheet "Sheet1". I thought the following should be able to extract it:

      string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Book1.xls;" + @"Extended Properties='Excel 8.0;HDR=Yes;'";
      using (OleDbConnection connection = new OleDbConnection(con))
      {
        connection.Open();

        OleDbDataAdapter da = new OleDbDataAdapter("Select * From [Sheet1$]", connection);

        DataTable dt = new DataTable();
        da.Fill(dt);

        dynamic cellA1 = dt.Rows[0][0].ToString();

But cellA1 is empty (""). Anyone know how to fix this, I should be able to treat it as a database and get cells from it?


Solution

  • "HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite. maybe thats the issue.