Getting the first sheet from an Excel document regardless of sheet name with OleDb

前端 未结 9 684
青春惊慌失措
青春惊慌失措 2020-12-29 02:23

I have users that name their sheets all sorts of crazy things, but I want to be able to get the first sheet of the Excel document regardless of what it is named.

I

9条回答
  •  半阙折子戏
    2020-12-29 02:53

    ended up using this:

    using (OleDbConnection conn = new OleDbConnection(connString))
    {
        conn.Open();
        dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
        Sheet1= dtSchema.Rows[0].Field("TABLE_NAME");
    }
    

提交回复
热议问题