c# - How to read cell values from existing excel file -


i want read each cell value in excel file, not able cell values after trying different examples in net. not getting result following code, can 1 on this. using .net framework 2.0

string filepath = "f:/bulktest.xlsx"; microsoft.office.interop.excel.application excelapp = new microsoft.office.interop.excel.application(); excelapp.visible = true; microsoft.office.interop.excel.workbook wb = excelapp.workbooks.open(filepath, 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);  microsoft.office.interop.excel.worksheet sh = (microsoft.office.interop.excel.worksheet)wb.sheets["sheet1"]; range excelrange = sh.usedrange;  (int i=2; i<= excelrange.count + 1 ; i++) {     string values = sh.cells[i,2].tostring(); } 

till trying take cell values directly variables, try take cell values array using range. thanks!!!! – teja varma 13 mins ago

no. didn't mean :) mentioned in comment can store entire range in array. doesn't mean need loop though each cell store in array. can directly assign values of range array. see example.

xlrng = xlworksheet.get_range("a1", "a20");  object arr = xlrng.value;  foreach (object s in (array)arr) {     messagebox.show(s.tostring()); } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -