【问题标题】:Applescript copy excel cells incrementally as a part of a workflowApplescript 增量复制 excel 单元格作为工作流程的一部分
【发布时间】:2014-09-20 00:35:58
【问题描述】:

我是这一切的新手,所以请多多包涵。

我在 Excel 电子表格的“B”列中有一个数字列表,我想使用 Applescript 一次复制一个,粘贴到另一个应用程序中,然后返回并复制列表中的下一个值.

我将 Automator 设置为选择一个单元格,然后复制到剪贴板。然后我插入了一个 AppleScript 将数字粘贴到另一个应用程序中,并进行了一些击键以完成输入。我已成功获得处理一个单元格的工作流程,但现在我想用下一个 Excel 单元格中的下一个数字重复该过程。

我真的不在乎我是否使用 Automator,我只是不知道如何编写脚本的 excel 部分。

谢谢(Mac X、Excel 2010)

【问题讨论】:

  • 检查“看我做”和 LOOP 自动操作。您可以保存和重播键盘事件。所以可能你需要:1)激活 Excel,2.)WatchMeDo 光标键向下到下一个单元格 3.)运行你当前的工作流程 4.)循环(重新开始)
  • 我今天和上周五的大部分时间都在网上寻找可以帮助我解决问题的示例。但没有人解决我正在寻找的所有标准。所以我决定在这里问我的问题。我已经熟悉了变量,但我没有看到任何关于引用 Excel 引用和将过程递增到下一个单元格的答案。
  • 我原以为从 Excel 中的一个单元格复制值、粘贴到某处并返回到下一个单元格、复制、粘贴到某处等是一项非常常见的任务。我可以找到你在哪里在你的代码中插入一个完整的列表,但我有成千上万的数字要处理,所以这似乎不切实际。 “看我怎么做”不会知道我在说什么,是往下走,不是吗?

标签: excel applescript increment automator


【解决方案1】:

您可能会发现将 Excel 值读入二维数组(AppleScript 列表列表)然后使用 AppleScript 循环遍历目标列中的值,而不是一个接一个地复制和粘贴值。这是一个如何完成的示例。

property targetCol : 2 --column B
property startRow : 2 -- if row 1 has headers
tell application "Microsoft Excel"
    tell active sheet
        set theData to used range's value --> list of lists 2D matrix
        set rowCount to count theData
        repeat with rowNum from startRow to rowCount
            set cellVal to item {targetCol} of item {rowNum} of theData
            -- do something with cellVal here --> write value to the other app, etc.
        end repeat
    end tell
end tell

【讨论】:

    【解决方案2】:

    在 Applescript 中,这只是模仿计算机上的击键:

    repeat 10 times
       activate application "Microsoft Excel"
       tell application "System Events" to tell process "Microsoft Excel"
          keystroke "c" using command down -- Command "c" (copies active cell to clipboard)
          key code 36 -- return button (to go down one cell)
       end tell
       activate application "Other App"
       tell application "System Events" to tell process "Other App" to keystroke "v" using command down -- Command "v" (pastes stored data from clipboard)
    end repeat
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      • 2017-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多