I am trying to import a row from excel sheet to C# like as array. I can read the excel program and open excel sheet but I can't apply the row to array. Thanks for any one that help me….
Excel.Application ex = new Excel.Application();
Excel.Workbook wb = ex.Workbooks.Open(@"D:\excel.xlsm");
Excel.Worksheet sheet = wb.Sheets[1];
Excel.Range range = sheet.get_Range("B23", "E23");
System.Array arr = (System.Array)(range.Cells.Value2);
// read it but not like array
for (int ii = 0; ii < arr.Length; ii++)
{
Console.Write(arr[ii] + " ");
}
You should iterate your System.Array
like so:
foreach (string a in arr)
{
Console.Write(a);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.