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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -