You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用AppleScript拆分Apple Numbers单列中的金额与日期数据

AppleScript 实现 Numbers 单列数据分组整理

脚本功能

把单列中每3行一组(金额、日期、空行)的数据,整理成A列存金额、B列存日期的一一对应格式。

完整脚本

tell application "Numbers"
    -- 检查是否有打开的Numbers文档
    if not (exists front document) then
        display alert "请先打开需要处理的Numbers文档"
        return
    end if
    set targetDoc to front document
    -- 默认取第一个工作表的第一个表格,若你的表格位置不同,修改数字即可
    set targetTable to table 1 of sheet 1 of targetDoc
    -- 假设数据在A列,若在其他列,把"A"改成对应列名(比如"B")
    set totalRows to count rows of column "A" of targetTable
    set destRow to 1
    
    -- 每3行一组遍历处理数据
    repeat with i from 1 to totalRows by 3
        -- 防止遍历到最后时超出总行数
        if i + 1 > totalRows then exit repeat
        
        -- 获取当前组的金额和日期值
        set amountValue to value of cell i of column "A" of targetTable
        set dateValue to value of cell (i + 1) of column "A" of targetTable
        
        -- 将数据写入对应目标列
        set value of cell destRow of column "A" of targetTable to amountValue
        set value of cell destRow of column "B" of targetTable to dateValue
        
        set destRow to destRow + 1
    end repeat
    
    -- 清理整理后多余的无效行
    set startCleanRow to destRow * 3
    if startCleanRow ≤ totalRows then
        delete rows startCleanRow through totalRows of targetTable
    end if
    
    display alert "数据整理完成!"
end tell

使用说明

  1. 打开需要处理的Numbers文档,确认数据在A列(若数据在其他列,修改脚本里的column "A"为对应列名,比如column "C")。
  2. 打开Mac自带的「脚本编辑器」(在启动台的「其他」文件夹中)。
  3. 复制粘贴上述脚本,点击工具栏的「运行」按钮(▶️)。
  4. 首次运行会弹出权限请求,允许「脚本编辑器」访问Numbers即可。

注意事项

  • 如果目标表格不是文档里的第一个表格,修改脚本中table 1的数字为对应表格序号(比如第2个表格就改成table 2)。
  • 建议先备份原文档再运行脚本,避免意外数据丢失。

内容的提问来源于stack exchange,提问作者Will Cloxton

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 00:32:02