c# - Get sheetnames from workbook -


i have following code .i sucessfully extract data each sheet in workbook :

foreach (var sheetname in getexcelsheetnames(connectionstring)) {     if (sheetname.contains("_"))     {     }     else     {          using (oledbconnection con = new oledbconnection(connectionstring))          {              var datatable = new datatable();              string query = string.format("select * [{0}]", sheetname);              con.open();              oledbdataadapter adapter = new oledbdataadapter(query, con);              adapter.fill(datatable);              ds.tables.add(datatable);          }     } } 

my goal extract sheetname in ds.

i try following code doesn't work

string query = string.format("select sheetname, * [{0}]", sheetname); 

how should modify ?

it seems useless thing me, should work:

string.format("select '{0}' sheetname, * [{0}]", sheetname); 

it pasts sheet name first field in query.

that assume know name, makes method useless. oledb doesn't have way sheet names in excel, need method if don't know names.


for having single-quoted sheet names, use this:

string.format("select '{1}' sheetname, * [{0}]", sheetname, sheetname.replace("'", "'''")); 

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -