i have created console application reads excel file. want take of document numbers , place in array searching purposes. able find cell contains data "documentnumber" e.g. $f$5. how can iterate through rows within column f? have following code:
public static void main(string[] args) { string address; string next; try { excel.applicationclass excel = new excel.applicationclass(); excel.workbook workbook = excel.workbooks.open(@"d:\sample.xls", missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value, missing.value); excel.worksheet worksheet = (excel.worksheet)workbook.sheets["sheet1"]; excel.range docnumber = worksheet.cells.find("documentnumber", worksheet.cells[1, 1], excel.xlfindlookin.xlvalues, excel.xllookat.xlpart, missing.value, excel.xlsearchdirection.xlnext, false, missing.value, missing.value); if(docnumber != null){ address = docnumber.get_address(true, true, excel.xlreferencestyle.xla1, missing.value, missing.value); console.writeline(address); } } catch (exception err) { console.writeline(err.message); } }
thanks in advance.
kindly this.it iterates through each , every rows , columns.
string address; string next; try { excel.applicationclass excel = new excel.applicationclass(); object missing = type.missing; fileinfo finfo = new fileinfo(@"d:\sample.xls"); if(finfo.exists) { excel.workbook workbook = excel.workbooks.open(@"d:\sample.xls", missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); excel.worksheet worksheet = (excel.worksheet)workbook.sheets["sheet1"]; excel.range docnumber = worksheet.cells.find("ddec", worksheet.cells[1, 1], excel.xlfindlookin.xlvalues, excel.xllookat.xlpart, missing, excel.xlsearchdirection.xlnext, false, missing, missing); if(docnumber != null) { address = docnumber.get_address(true, true, excel.xlreferencestyle.xla1, missing, missing); docnumber = worksheet.usedrange; (int rcnt = 1; rcnt <= docnumber.rows.count; rcnt++) { (int ccnt = 1; ccnt <= docnumber.columns.count; ccnt++) { string str = (string)(docnumber.cells[rcnt, ccnt] excel.range).value2; messagebox.show(str); } } console.writeline(address); } } }
Comments
Post a Comment