2014-11-09 88 views
0

有人可以幫我刪除錯誤嗎?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 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 

謝謝!

回答

1

基本上,當單元格沒有任何值時會發生這種情況,因此表中必須有一些空行。最簡單的做法是使用一個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