c# - Get excel sheet names using Getschema method without sorting -
i inserting data sql table excel sheet. oledbconnection.getschema("table_name")
getting excel sheet names in sorted order. dont want them sorted coz want first sheet in order perform operations on it. here code snippet.
string con = "provider=microsoft.ace.oledb.12.0;data source=" + excel +";extended properties=\"excel 12.0;hdr=yes;imex=2\""; oledbconnection cn = new oledbconnection(con); cn.open(); datatable sheettable = cn.getschema("tables"); string strsheetname = convert.tostring(sheettable.rows[0]["table_name"]);
any highly appreciated.
try code, worked me...
microsoft.office.interop.excel.application xlapp = new microsoft.office.interop.excel.application(); microsoft.office.interop.excel.workbook excelbook = xlapp.workbooks.open(filepath); string[] excelsheets = new string[excelbook.worksheets.count]; int = 0; foreach(microsoft.office.interop.excel.worksheet wsheet in excelbook.worksheets) { excelsheets[i] = wsheet.name; i++; }
*replace "filepath" file location path...
Comments
Post a Comment