如何使用AppleScript迭代excel表?

时间:2018-06-08 18:51:06

标签: excel applescript

我是AppleScript的新手,所以这可能是也可能不是一个明显的问题。我需要遍历一个excel电子表格,其中每一行都是一个设备,列是我需要获得的有关该设备的信息。本质上它是一个嵌套的for循环,我遍历行,每行我遍历所有列。有人知道怎么做这个吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

下面。这样就可以了:

 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

我希望它有所帮助。