2013-04-13 37 views
1

我正在寫一個applescript來處理XML的電子表格,它幾乎已經完成了,但是我發現只要它從一個單元格中檢索值,並且該值是一個數字,它用十進制格式化它。AppleScript/Excel我想丟失小數答案

4變成4.0

我該如何強制它只得到整數?數字不是它將獲得的唯一價值。

下面是相關代碼:

-- Copy field from SS 
    tell application "Microsoft Excel" 
     activate 
     goto reference cellNum 
     set GotValue to value of active cell as string 
     delay 0.3 
     --tell application "System Events" to keystroke "c" using command down 
     delay 2 
    end tell 

而且我知道我可以通過劃定和小數點前只保留了第一部分的函數處理它,但就像我說的,不是數字更多的東西通過這個,段落也可以。所以這不會很好。

回答

1

對於任何人來說,這是通過一個函數來檢查輸入是否是實數,如果是,則將其轉換爲整數,然後將其轉換爲字符串。像這樣:

on isReal(x) 
    return ({class of x} is in {real}) 
end isReal 

if isReal(GotValue) then 
     set GotValue to GotValue as integer 
    end if 
    set GotValue to GotValue as string