我正在寻找关于AppleScript的帮助(不幸的是,工作原因仅限于AppleScript)。具体来说,我无法弄清楚如何在Excel列中复制并粘贴每个单元格时循环访问excel列。AppleScript,循环遍历列(直到空),复制并粘贴到网络表格
这里是我做到目前为止有:
to clickID(theId) -- clickID function start
tell application "Safari"
do JavaScript "document.getElementById('" & theId & "').click();" in document 1
end tell
end clickID
--__________________________________________
tell application "Microsoft Excel"
activate
open "Filepath/Starfox Tester.xlsx" --changed filename for privacy
get active workbook
select cell "A2" --Headers will be in column A1, hence why selecting A2
tell application "System Events" to tell process "Microsoft Excel" to keystroke "c" using command down
end tell
do shell script "open -a Safari 'https://google.com'"
delay 2 --for website to load
clickID("lst-ib")
tell application "System Events" to tell process "Safari" to keystroke "v" using command down
到目前为止,这工作;我了解如何手动执行此操作,但由于每次运行此脚本时,我的列都有不同数量的行,因此我需要它能够循环直到找到空单元格。
任何帮助将不胜感激!谢谢!
更新: 我认为最简单的方法可能是if else循环。我的基本想法是运行一个处理程序(函数),如果引用中的单元格不是空白的。由于我可能不会超过50个单元格,因此我计划在(A1 - A50)中对其进行硬编码并每次运行处理程序。
我目前正试图弄清楚如何编写处理程序。以下是我迄今为止:
to populateVal(cellValue)
tell application "Microsoft Excel"
get active workbook
select cellValue
tell application "System Events" to tell process "Microsoft Excel" to keystroke "c" using command down
activate Safari
clickID("lst-ib")
tell application "System Events" to tell process "Safari" to keystroke "c" using command down
end tell
end populateVal
do shell script "open -a Safari 'https://google.com'"
tell application "Microsoft Excel"
activate
open "Filepath/Starfox Tester.xlsx"
if cell "A2" ≠ "" then
populateVal("A2")
else
display dialog "Done!"
end if
end tell
我目前得到一个错误说,创先争优“无法继续populateVal”。如果我拿掉A2的圆括号,我会得到一个错误,说A2“没有定义”。任何帮助,将不胜感激!