我是Apple的新手,对此的任何帮助都将受到高度赞赏。我认为对于拥有比我更多技能的人来说,这将是一个很好的挑战。所有描述都是在Snow Leopard和MS Office 2011中完成的。
我有一个URL列表(从单元格Q2开始)我已经获得了AppleScript来执行以下一系列任务:
我已将下面的脚本放在一起,这样就可以了。麻烦的是我无法重复它。重复函数需要重复执行整个脚本,首先将单元格Q2更改为Q3,依此类推,直到最后一个单元格包含值0,这是结束循环的信号,并使用名称保存每个工作簿按顺序排列(workbook002,然后是workbook003等)。我不认为firefox部分需要改变,因为步骤总是一样的。
这是脚本:
do shell script "open -a /Applications/Microsoft\\ Office\\ 2011/Microsoft\
\ Excel.app ~/Desktop/KospiSection2.xlsx"
tell application "Microsoft Excel"
set sourceBook to workbook "Section2.xlsx"
set sourceRange to get range "Q2" of sheet 1 of sourceBook
copy range sourceRange
end tell
tell application "Firefox"
activate
tell application "System Events"
tell process "Firefox"
click menu item "PasteGo" of menu "Tools" of menu bar 1
delay 3
click menu item "View1" of menu "View" of menu bar 1
delay 10
click menu item "View2" of menu "View" of menu bar 1
delay 2
click menu item "Copy all Tables (2)" of menu "Edit" of menu bar 1
delay 3
click menu item "Close Tab" of menu file of menu bar 1
end tell
end tell
end tell
tell application "Microsoft Excel"
make new workbook
delay 2
tell active sheet of active workbook
paste worksheet destination range "A1"
delay 2
end tell
end tell
do shell script "save as -a /Applications/Microsoft\\ Office\\ 2011/Microsoft\\
Excel.app ~/Desktop/workbook002.xlsx"
真诚地感谢任何人都可以弄清楚如何做到这一点。很长一段时间以来,我一直在思考这个问题。 附:如果有人知道一本关于使用applescript运行excel的好书,请告诉我。
再次感谢!
答案 0 :(得分:0)
好吧...... 你需要的东西:
range "Q2" of sheet 1 of sourceBook
应该在range "Q3" of sheet 1 of sourceBook
在AppleScript术语中,您将编写如下行:
set sourceRange to get range ("Q" & i) of sheet 1 of sourceBook
并处理“i”变量。 请注意,此“i”变量也将出现在工作簿的名称中
"workbook002.xlsx"
变为("workbook00" & i & ".xlsx")
tell application "Microsoft Excel"
set sourceBook to workbook "Section2.xlsx"
repeat with i from 2 thru 20
set sourceRange to get range ("Q" & i) of sheet 1 of sourceBook
...
set outputFileName to "workbook00" & i & ".xlsx" -- Well there should be some work on the name so that it looks like what you expect, but that's another thing)
save workbook as active workbook filename ({path to desktop folder as string, outputFileName} as string) with overwrite -- keep the 'save as' action within the loop, and within the "tell Excel"
end -- repeat
set sourceBook to workbook "Section2.xlsx"
repeat with i from 2 thru 20
set sourceRange to get range ("Q" & i) of sheet 1 of sourceBook
...
set outputFileName to "workbook00" & i & ".xlsx" -- Well there should be some work on the name so that it looks like what you expect, but that's another thing)
save workbook as active workbook filename ({path to desktop folder as string, outputFileName} as string) with overwrite -- keep the 'save as' action within the loop, and within the "tell Excel"
end -- repeat
这应该可以解决问题......