excel - 如何使用 AppleScript 遍历 excel 工作表?
问题描述
我是 AppleScript 的新手,所以这可能是也可能不是一个明显的问题。我需要遍历一个 excel 电子表格,其中每一行是一个设备,而列是我需要获取的有关该设备的信息。本质上,它是一个嵌套的 for 循环,我在其中遍历行,并且对于每一行,我都遍历其所有列。有人知道怎么做这个吗?提前致谢。
解决方案
这里。这将做到这一点:
set NumOfColumns to 5
set NumOfRows to 5
tell application "Microsoft Excel"
tell document 1
tell worksheet 1
--to iterate through rows
repeat with z from 1 to NumOfRows
--to iterate through columns
repeat with i from 1 to NumOfColumns
--to set a value (here it is adding a number "i as a string".
--I know, you are not asking how to set a value, but here it is anyway!)
set value of column i of row z to (i as string)
--to retrieve a value (here it is copying the number to a variable ValueX)
set ValueX to (value of cell i of row z)
end repeat
end repeat
end tell
end tell
end tell
我希望它有所帮助。
推荐阅读
- c++ - 宏 #define 函数语法得到“'{' 标记之前的预期表达式。”
- python - 如何通过 OAuth2 获取授权令牌并通过 http 请求读取 Outlook 电子邮件?
- mysql - MySQL 正则表达式验证电子邮件不起作用 - 大括号量词被忽略
- java - 如果查询条件满足 JPA 和 spring,则插入行
- css - 如何根据显示的大小改变css
- r - 在 Actor-Actor 网络中找到六度分离
- python - 为什么我无法使用 python、pytesseract、cv2 从图像中识别简单的字母文本
- visual-studio - 为解决方案生成代码图 - 无法连接到指定的数据库
- python - 我在 Tensorflow 上做错了什么?
- python - 如何将多个 csv 文件整理成一个 csv 文件,每次都删除标题?