applescript to compare cell values and then place the value of one cell into another

跟風遠走 提交于 2019-12-13 05:18:57

问题


in a numbers app table i have the following data

   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

i am trying to write an applescript that will...

  1. iterate down logins in column D
  2. to find a matching login in column B
  3. take the value of the user_id in column A at the row where the match was found
  4. and place it into column C in the same row as the entry in column D
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:


AppleScript may be superfluous for what you're trying to do. In the numbers documentation, take a look at the VLOOKUP function, which is passed a value to look up, a set of cells to look up in, and the column of the value to return. I got it to work only by swapping the order of the user_id and login columns, but once I put the login in column A and the user_id in column B, setting cell C1=VLOOKUP(D2, A2:B7, 2 ) returned 121 successfully.



来源:https://stackoverflow.com/questions/5262393/applescript-to-compare-cell-values-and-then-place-the-value-of-one-cell-into-ano

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!