簡體   English   中英

將行從Excel文件導入數組到C#

[英]importing array from row excel file to c#

我試圖將行從excel工作表導入到C#,如數組。 我可以閱讀excel程序並打開excel表,但不能將行應用於數組。 謝謝任何幫助我的人。

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] + " ");
         }

您應該像這樣迭代System.Array

foreach (string a in arr)
{
    Console.Write(a);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM