来自excel回音值的Applescript数据然后递增

时间:2013-08-19 14:30:59

标签: applescript

所有我正在尝试制作一个从excel电子表格单元格号B2读取数据的苹果脚本,并将var1设置为B2的值,但我希望它检查单元格A2系统所处的时间匹配A2的值,如果匹配,则取B2的值并将其设置为变量。

这将是第一次第二次从A3&收集数据B3

   set SystemTime to (current date)

   set current_row to 2 #Set starting row
   repeat
tell application "Microsoft Excel"
    set a_cell to (get value of cell (("A" & current_row) as string)) #Get A cell val
    if a_cell = SystemTime then #If times match up
        set b_cell to (value of cell (("B" & current_row) as string)) #Get B         cell val
        display dialog b_cell #Display that val
        current_row = current_row + 1 #Increment the row we're looking at

    end if
  end tell
end repeat

1 个答案:

答案 0 :(得分:0)

您的单元格名称必须是字符串(引号),并且需要将它们转换为单元格对象(即cell "A2")。当您要求脚本第二次从A3B3收集数据时,我不确定您的意思,它什么时候会这样做?在别的?如果没有,如果A2 与系统时间不匹配,您希望发生什么?截至目前,我已经等了两分钟,然后再试一次......请更清楚你要找的是什么。

repeat
    tell application "Microsoft Excel"
        set a2 to (get value of cell "A2") 
        if a2 = SystemTime 
            set var to (Value of cell "B2")
            display dialog var
            exit repeat
        else
            delay 120 #wait 2 minutes
        end if
    end tell
end repeat

修改

好的,在您的评论之后(假设您希望在两次检查之间等待2分钟):

set current_row to 2 #Set starting row
repeat
    tell application "Microsoft Excel"
        set a_cell to (get value of cell (("A" & current_row) as string)) #Get A cell val
        if a_cell = SystemTime then #If times match up
            set b_cell to (value of cell (("B" & current_row) as string)) #Get B cell val
            display dialog var #Display that val
            current_row = current_row + 1 #Increment the row we're looking at
        else
            delay 120 #wait 2 minutes
        end if
    end tell
end repeat