我试图遍历Excel中的所有行,并在每一行上运行一些命令,但我不知道如何执行!
我最初尝试在rb-appscript ( Applescript的Ruby包装器)中这样做,但我决定在添加另一个领域特定语言之前先在Applescript中尝试让它工作会更好。有什么建议吗?( rb-appscript版本也不错,但不是必需的)。
谢谢!
发布于 2011-08-15 22:41:25
范围的坐标是可以动态创建的字符串。遍历行的最简单方法如下所示:
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每条评论的更新:为了获得需要计算的行数,我在很久以前写了一个子例程来帮助实现这一点。确保您有某种类型的“键”列被一致地填充(换句话说,没有跳过的单元格)。这当前考虑了标题行,因为我的所有电子表格都有标题行:
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
repeat with thisRow from 2 to lastRow + 1
-- go attack Excel
end repeathttps://stackoverflow.com/questions/7061865
复制相似问题