c# - Get all sheet names in an Excel file in order -
this question has answer here:
i trying sheet names in same order in excel file array. reach sheet individually below:
var pathtoexcel = @"c:\users\desktop\everything.xlsx"; var sheetname = "sheet 1"; var destinationpath = @"c:\users\desktop\sheet1.json"; var connectionstring = string.format(@" provider=microsoft.ace.oledb.12.0; data source={0}; extended properties=""excel 12.0 xml;hdr=yes"" ", pathtoexcel);
i wondering how sheet names in array.
try this,
oledbconnection conn = new oledbconnection(connectionstring); conn.open(); datatable dt = conn.getoledbschematable(oledbschemaguid.tables, null); string[] sheetnames = new string[dt.rows.count]; int = 0; foreach (datarow row in dt.rows) { sheetnames[i] = row["table_name"].tostring(); i++; }
Comments
Post a Comment