0

我正在尝试制作一个从 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
4

1 回答 1

0

您的单元格名称需要是字符串(用引号括起来),并且需要转换为单元格对象(即cell "A2")。A3当您询问脚本第二次从and收集数据时,我不确定您的意思是什么B3,它什么时候会这样做?在别的?如果不是,如果与系统时间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
于 2013-08-19T16:55:18.693 回答