Reading multiple Excel worksheets inside a single xlsx using c# -
this question has reply here:
reading multiple excel sheets different worksheet names 1 replyusing c# can open excel document , read info in first worksheet code below. however, .xlsx has multiple worksheets loop through worksheet collection rather hard coding name of each worksheet. many thanks.
string path = @"c:\extract\extract.xlsx"; string connstr = "provider=microsoft.ace.oledb.12.0;data source=" + path + ";extended properties=excel 12.0;"; string sql = "select * [sheet1$]"; using (oledbdataadapter adaptor = new oledbdataadapter(sql, connstr)) { dataset ds = new dataset(); adaptor.fill(ds); datatable dt = ds.tables[0]; }
i'm work on same problem. found guide @ http://www.dotnetperls.com/excel quite useful.
in short, open worksheet no. 3, add together next code after opening excel workbook:
var worksheet = workbook.worksheets[3] microsoft.office.interop.excel.worksheet;
hope answered question.
c# excel
No comments:
Post a Comment