【问题标题】:Count rows and columns that contains data from DataTable in C#.net获取(计数)Excel文件使用的行数和列数(以数据表计)
【发布时间】:2012-05-28 23:29:18
【问题描述】:

我在我的数据表中导入了一个 excel 文件。 出于某种原因,我需要计算我的总行数和列数。 在我的 excel 文件中,我刚刚使用了 3 行,在 A 列和 20、21、22 行的 3 个单元格中给出了 1、2、3。

现在1到19的行不使用,22以下的也不使用,同样,我没有使用B列到典型的excel文件的末尾,只使用了A。

因此,正确答案是 Rows.Count = 3 和 Columns.Count = 1。

现在,我想计算我使用的那个 DataTable 的行和列。请告诉我该怎么做。

【问题讨论】:

    标签: c# excel datatable count


    【解决方案1】:

    不会有一个标志告诉您“此行是否已使用标志”您需要做的是确定在这种情况下不会使用的行中的值 1-19, 22 you需要决定检查一行中的一列是否足够,或者您是否需要检查该列中的所有行以查看该行是否被使用。假设我知道如果 MemberShipNumber 等于 null 或 "" 那么我知道整行不会被使用,这就是我将如何进行检查:

      foreach(DataRow dr in table)
      {
    
         if (string.String.IsNullOrEmpty(dr["MembershipNumber"]))
         {
             Console.Write("This row is empty");
         } 
         else
         {
             Console.Write("This row is not empty there is more processing to do.");
         }
      }
    

    希望有帮助

    【讨论】:

      猜你喜欢
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多