2012-12-05 33 views
0

這聽起來很簡單(我確信它是這樣),但我不知道如何做到這一點: 我有一個表中的數據excel - 讓我們說兩列:列A包含ID,列B包含電子郵件地址。Applescript在Excel中找到一個值,然後在同一行中查找另一個值

我正在尋找一個Applescript,它將打開數據庫文件並在一列中查找ID,但返回第二列的值供我稍後在腳本的其餘部分使用。

這是我迄今:

set theFile to POSIX path of (choose file with prompt "Choose File to Operate on") 
tell application "Microsoft Excel" 
activate 
open theFile 
set searchRange to range ("A1:D2") 
try 
    set foundRange to find searchRange what "ID1" with match case 
    (* do something with the foundRange *) 
on error -- not found 
    (* do error handling *) 
end try 
end tell 

不知道如何獲取到第二列,並返回一個值,即。設置爲IDEmail?

回答

1

嘗試:

tell application "Microsoft Excel" 
    set searchRange to range ("A1:A5") 
    set foundRange to find searchRange what "ID3" with match case 
    set fRow to first row index of foundRange 
    set myData to value of range ("B" & fRow as text) 
    (* do something with the foundRange *) 
end tell 

enter image description here

相關問題