my code opens first sheet of excel. target open sheet selected in combobox. can me find solution:
my code:
string currsheet = combobox1.selecteditem.tostring(); microsoft.office.interop.excel.application xap = new microsoft.office.interop.excel.application(); xap.visible = true; microsoft.office.interop.excel.workbook wk = xap.workbooks.open(path3,0, false, 5, "", "", false, microsoft.office.interop.excel.xlplatform.xlwindows, "", true, false, 0, true, false, false); microsoft.office.interop.excel.sheets excelsheet = wk.worksheets; microsoft.office.interop.excel.worksheet wsh = (worksheet)excelsheet.get_item(currsheet);
by sheet name
microsoft.office.interop.excel.worksheet wsh = (worksheet)excelsheet["sheetname"];
by index (starting 1 - first sheet)
microsoft.office.interop.excel.worksheet wsh = (worksheet)excelsheet[1];
just use 1 of values in combobox. if want populate combo box available sheets, can go throug worksheets
foreach (worksheet sh in excelsheet) { combobox.items.add(sh.name); }
then, combobox selected value sheet name, by:
microsoft.office.interop.excel.worksheet wsh = (worksheet)excelsheet[combobox.selectedvalue]; //i'm not sure if combobox value got this, excel part ok.
Comments
Post a Comment