string filename = "your filename";
string connectionString;
connectionString = "Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};dbq=" + filename + ";fil=excel 12.0;readonly=0;usercommitsync=Yes";
OdbcConnection myConnection = new OdbcConnection(connectionString);
myConnection.Open();
DataTable data = myConnection.GetSchema("Tables");
myConnection.Close();
List sheets = new List();
foreach (DataRow sheet in data.Rows)
{
sheets.Add(sheet["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$'));
}
P.S. I have built a whole static class library to read and write excel sheets I will post it here when I have some time to comment it.
No comments:
Post a Comment