3

我正在尝试使用 AppleScript 复制数字文件中的工作表(我每天都需要基于模板的新工作表)。我对 AppleScript 真的很陌生,但我已经在使用它来填充一些单元格,其中包含我从运行的 python 脚本中获得的结果,但这一点仍然是手动的...... =/

tell application "Numbers"
tell document 1
    set thisSh to make new sheet with properties {name:"May14"}
    duplicate sheet "Template" to sheet "May14"
end tell
end tell

上面的代码返回错误:error "Numbers got an error: Sheets can not be copied." number -1717因此,我的问题是:有没有办法复制数字表?

我目前正在运行编号为 3.2 的 iWork '14

谢谢!

PS我也尝试duplicate every table of sheet "Template" to sheet "May14"过类似的错误:Tables can not be copied.

4

1 回答 1

2

你有两个选择。您可以以编程方式在新工作表中构建表格,或者您可以从第一张工作表中选择并复制表格并将其复制到新工作表中。这是第二个选项的代码。没有看到模板表的屏幕截图,您可能需要进行调整,但这应该会为您提供所需的一切。如果您遇到复杂情况,请发布您的模板表的屏幕截图和说明。 更新以考虑工作表中的大量表格。再次更新以演示如何更改活动工作表。

tell application "Numbers"
    activate
    tell document 1
        set tempSheet to first sheet whose name is "My Template"
        set active sheet to tempSheet
        tell application "System Events"
            -- deselect all
            keystroke "a" using {command down, shift down}
            delay 0.1
            -- select all containers (tables, text items, etc.)
            keystroke "a" using {command down}
            delay 0.1
            -- copy the containers
            keystroke "c" using {command down}
        end tell
        delay 0.1
        set dateString to (month of (current date)) & (day of (current date)) as string
        set thisSheet to make new sheet with properties {name:dateString}
        tell thisSheet
            delete every table
            tell application "System Events"
                keystroke "v" using {command down}
            end tell
        end tell
    end tell
end tell
于 2014-05-22T18:26:48.683 回答