首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Applescript遍历Excel中的所有行?

如何使用Applescript遍历Excel中的所有行?
EN

Stack Overflow用户
提问于 2011-08-15 13:08:37
回答 1查看 4.6K关注 0票数 2

我试图遍历Excel中的所有行,并在每一行上运行一些命令,但我不知道如何执行!

我最初尝试在rb-appscript ( Applescript的Ruby包装器)中这样做,但我决定在添加另一个领域特定语言之前先在Applescript中尝试让它工作会更好。有什么建议吗?( rb-appscript版本也不错,但不是必需的)。

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-15 22:41:25

范围的坐标是可以动态创建的字符串。遍历行的最简单方法如下所示:

代码语言:javascript
复制
repeat with thisRow from 1 to 10
    tell application "Microsoft Excel"
        set theRange to "A:" & thisRow & "Z:" & thisRow
        set theValue to (get value of range theRange) as list
        -- do something with the row's data
    end tell
end repeat

每条评论的更新:为了获得需要计算的行数,我在很久以前写了一个子例程来帮助实现这一点。确保您有某种类型的“键”列被一致地填充(换句话说,没有跳过的单元格)。这当前考虑了标题行,因为我的所有电子表格都有标题行:

代码语言:javascript
复制
on GetItemCount(KeyColumn)
    set RowNumber to 1
    set theText to "cSyoyodylg" -- dummy value
    tell application "Microsoft Excel"
        repeat until theText is ""
            set RowNumber to RowNumber + 1
            set theRange to KeyColumn & RowNumber & ":" & KeyColumn & RowNumber
            set dataRange to range theRange of sheet 1
            set theText to (get value of range theRange)
        end repeat
    end tell
    set rowCount to RowNumber - 1
    return rowCount
end GetItemCount

简单地这样做:将lastRow设置为GetItemCount("A") of me

代码语言:javascript
复制
repeat with thisRow from 2 to lastRow + 1
    -- go attack Excel
end repeat
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7061865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档