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 currently use:
OleDbDataAdapter adapter = new OleDbDataAdapter( "SELECT * FROM [sheetName$]", connString);
How would I go about getting the first sheet no matter what it is named?
Thank you.
Using the + symbol in Excel Start by selecting the target cell (in our case B1 of Sheet 2) and typing in the + symbol. Next, right-click on the Sheet 1 label button to go back to your data. Select cell A1 and then press Enter. Your data will be automatically copied into cell B1.
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<string>("TABLE_NAME"); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With