如何比较同一工作簿的不同工作表中的字符串 [英] How to compare strings in different worksheets of same workbook

查看:73
本文介绍了如何比较同一工作簿的不同工作表中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试这样的比较不同工作表的列





Hi,

I am trying something like this to compare the columns of different work sheets


i = 1;
           foreach (DataRow row in lstDS[0].Tables[0].Rows)
           {


               string fieldFromDB = row[1].ToString();
               foreach (DataRow row1 in lstDS[1].Tables[0].Rows)
             {
                 string fieldFromDB1 = row[1].ToString();

                 if (fieldFromDB == fieldFromDB1)
                   {

                       xlWorkSheet2.Cells[i, 1] = row[8];
                       xlWorkSheet2.Cells[i, 2] = row1[8];

                   }

                 i++;

             }
           }







但是这段代码用另一行编写了列的每一行的所有可能性。



但我需要做一些事情,如果字符串相等,那么写一些excel表格中同一行的值

任何人都可以建议我怎么做?





谢谢,

John




But this code is writing all the possibilities of each row of the column with the other.

But I need to do something like, if the strings are equal, then write some values of the same row into the excel sheet
Can any one suggest me, how this can be done???


Thanks,
John

推荐答案

嗯。

当你不这样做时,这就是问题使用有意义的名字......

Um.
That's the problem when you don't use meaningfull names...
foreach (DataRow row in lstDS[0].Tables[0].Rows)
   {
   string fieldFromDB = row[1].ToString();
   foreach (DataRow row1 in lstDS[1].Tables[0].Rows)
      {
      string fieldFromDB1 = row[1].ToString();



也许是一个小改动:


Perhaps a small change:

foreach (DataRow row in lstDS[0].Tables[0].Rows)
   {
   string fieldFromDB = row[1].ToString();
   foreach (DataRow row1 in lstDS[1].Tables[0].Rows)
      {
      string fieldFromDB1 = row1[1].ToString();
                               ^
                               |


这篇关于如何比较同一工作簿的不同工作表中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆