applescript用于比较单元格值,然后将一个单元格的值放入另一个单元格中

时间:2011-03-10 16:09:16

标签: applescript iwork

在数字app表中我有以下数据

   A          B                     C                 D
user_id     login                user_id        login
2039        Abbott, Rachael                     Adams, Sue
110         Abbott, Shelby                      Adamson, Wendy
2910        Abraham, Binu                       Anderson, Daryl
121         Adams, Sue
122         Adamson, Anne
126         Adamson, Wendy

我正在尝试编写一份将会......的文章。

  1. 迭代D列中的登录
  2. 在B列中找到匹配的登录信息
  3. 获取匹配项所在行A列中user_id的值
  4. 并将其放入与列D
  5. 中的条目相同的行中的C列
    set dName to "correlationstudies.numbers"
    set sName to "users"
    set tName to "Table 1"
    set login_row to 2
    set login_w_id_row to 2
    
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
       repeat
          set login to value of cell login_row of column 4
          if login = "" then exit repeat
          set login_w_id_row to 2
    
          repeat
             set logincomp to value of cell login_w_id_row of column 2
             if logincomp = login then
                set value of cell login_row of column 3 to value of cell login_w_id_row of column 1
                exit repeat
             end if
             set login_w_id_row to login_w_id_row + 1
          end repeat
          set login_row to login_row + 1
       end repeat
    end tell
    

1 个答案:

答案 0 :(得分:1)

AppleScript对于您正在尝试的操作可能是多余的。在数字文档中,查看VLOOKUP函数,该函数传递一个要查找的值,一组要查找的单元格以及要返回的值的列。我只是通过交换user_id和登录列的顺序才能使用它,但是一旦我将登录放在A列中,而将user_id放在B列中,设置单元格C1 = VLOOKUP(D2,A2:B7,2)就成功返回121