如何创建从excel文件读取的动态并行数组? C#

时间:2015-06-17 14:01:01

标签: c# arrays excel io

我正在尝试将特定的数据行读入数组,将另一行(行A)读入其自己的数组中。我知道如何让我的excel文件读取但我不知道如何将特定行放入数组....请帮助我理解如何声明两个动态并行数组!

  //Checks if the ID Number Matches
            string value = EmployeeIDTextbox.Text;
            Match match = Regex.Match(value, @".*[0-9].*");
            Console.WriteLine(value);
            int TotalRows = xlsDs.Rows.Count;
            for (int i = 0; i < TotalRows; i++)
            {
                DataRow row = xlsDs.Rows[i];

                //Cell Name that contains ID Number
                String row_Val = row["Enter Employee ID number"].ToString(); 

                Match myMatch = Regex.Match(row_Val, EmployeeIDTextbox.Text);

                //If ID Number is found
                if (match.Success && myMatch.Success)
                {
                    Console.WriteLine(EmployeeIDTextbox);

                    //Place Employee information in array

                    //Places Coloumn headers in array

1 个答案:

答案 0 :(得分:0)

您已经可以像这样的数组访问行值:

var rowValues = row.ItemArray;

可以将列标题转换为如下数组:

using System.Linq;
using System.Data;
....
var columnHeaders = table.Columns
    .Cast<DataColumn>()
    .Select(x => x.ColumnName)
    .ToArray();