1

所以我正在将一个 excel 文档导入我的项目

DataSet result = excelReader.AsDataSet();

 if (result != null)
            {
                foreach (System.Data.DataTable t in result.Tables)
                {
                    if (t != null && t is System.Data.DataTable)
                    {
                        System.Data.DataTable table = t as System.Data.DataTable;

                        Items Lastitem = new Items();

                        foreach (System.Data.DataRow r in t.Rows)
                        {
                            if (r != null && r is System.Data.DataRow)
                            {
                                //new ItemType
                                if (r.ItemArray[0] != null)
                                {

然后我运行检查以检查当我得到空列时哪一列是空的,然后我想得到空行。我努力了:

if (checkIfColumnisEmpty(r.ItemArray[0]) && !checkIfColumnisEmpty(r.ItemArray[1]))
                                        {
                                            throw new ImportBOQException("Error importing document: First column is empty at row " + r);

r 作为数据行,telesense 允许我 rowError、rowState 等...但不是行号....有什么想法吗?}

4

1 回答 1

1

您可以在遍历行时使用 aFor Loop而不是,如下所示:Foreach

for (int i = 0; i < t.Rows.Count; i++)    
{

    // Do Your Null Checking and throw the exception with iteration number + 1

    if (checkIfColumnisEmpty(t.Rows[i].ItemArray[0]) && !checkIfColumnisEmpty(t.Rows[i].ItemArray[1]))
       {
          throw new ImportBOQException("Error importing document: First column is empty at row " + (i + 1));
       }
}
于 2013-01-21T13:03:54.560 回答