【问题标题】:Duplicate a numbers sheet with applescript使用 applescript 复制数字表
【发布时间】:2014-05-13 12:56:35
【问题描述】:

我正在尝试使用 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

谢谢!

附:我还尝试了duplicate every table of sheet "Template" to sheet "May14",但出现了类似的错误:Tables can not be copied.

【问题讨论】:

  • 你有哪个版本的 Numbers?
  • @GrzegorzAdamKowalski,我使用的是 Numbers 3.2

标签: macos applescript iwork


【解决方案1】:

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

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

【讨论】:

  • 我将在今天晚些时候测试类似的东西,但它可能不会真正有帮助,因为我每张表有 17 个表格(所有表格都带有隐藏单元格)。所以它可能会一团糟......
  • 别这么悲观;你会明白的。 :) 我添加了更多代码来帮助演示更多。如果您仍有问题,请发布。
  • 效果很好! xD 但是,我的模板表必须处于活动状态,如果前面有任何其他表,那将是复制的。 (我认为“触摸”黑客可以解决这个问题,但没有。=/)
  • 添加了set active sheet line,解决了这个问题。另外,向您展示了另一种复制所有元素的方法。您可以取消选择工作表中的所有内容,然后选择所有内容,而不是触摸容器黑客。让我知道它是如何工作的。如果您感谢帮助,请务必接受答案。
  • 太棒了!这样就彻底解决了!我只是不明白为什么你不能用duplicate 复制它们,因为你可以通过右键单击工作表名称来复制它们......无论如何,谢谢你的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-27
  • 2014-07-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-26
相关资源
最近更新 更多