AppleScript中缺少值

AppleScript中缺少值,applescript,Applescript,有人能帮我消除这个错误吗 错误“缺失值无法转换为类型编号。”编号-1700从缺失值转换为编号 tell application "Numbers" activate open theFile tell the first table of the active sheet of document 1 repeat with i from 2 to the count of rows of column "D" set val1 to

有人能帮我消除这个错误吗

错误“缺失值无法转换为类型编号。”编号-1700从缺失值转换为编号

tell application "Numbers"
    activate
    open theFile
    tell the first table of the active sheet of document 1
        repeat with i from 2 to the count of rows of column "D"
            set val1 to value of cell i of column "D"
            set the value of cell i of column "D" to val1 * -1
        end repeat
    end tell
end tell

谢谢大家!

基本上,当单元格没有任何值时会发生这种情况,因此表中必须有一些空行。最简单的方法是使用一个try块,当您不能将val1乘以-1时,它将忽略所有错误

tell application "Numbers"
    activate
    open theFile
    tell the first table of the active sheet of document 1
        repeat with i from 2 to the count of rows of column "D"
            set val1 to value of cell i of column "D"
            try
                set the value of cell i of column "D" to val1 * -1
            end try
        end repeat
    end tell
end tell