2014-05-13 36 views
2

我想使用AppleScript在數字文件中複製工作表(我需要每天基於模板創建一個新工作表)。 我真的很新的AppleScript,但我已經用它來填補,在某些細胞的結果,我從一個Python腳本我運行得到但這一點仍然是手動... =/使用AppleScript複製數字表

tell application "Numbers" 
tell document 1 
    set thisSh to make new sheet with properties {name:"May14"} 
    duplicate sheet "Template" to sheet "May14" 
end tell 
end tell 

的上面的代碼返回錯誤:error "Numbers got an error: Sheets can not be copied." number -1717,因此,我的問題:有沒有辦法複製數字表?

我目前正在使用數字3.2運行iWork '14 3.2

謝謝!

P.S.我也試過duplicate every table of sheet "Template" to sheet "May14",有類似的錯誤:Tables can not be copied.

+0

你有哪個版本的Numbers? –

+0

@GrzegorzAdamKowalski,我正在使用Numbers 3.2 – pekapa

回答

1

你有兩個選擇。您可以以編程方式在新工作表中構建表格,也可以從第一個工作表中選擇並複製工作表並將其複製(他們)到新工作表中。這是第二個選項的代碼。沒有看到你的模板表的屏幕抓取,你可能需要調整,但這應該給你你需要的一切。如果遇到複雜情況,請發佈模板的屏幕截圖和說明。 更新了來解釋工作表中瘋狂的表格數量。 再次更新以演示如何更改活動工作表。

tell application "Numbers" 
    activate 
    tell document 1 
     set tempSheet to first sheet whose name is "My Template" 
     set active sheet to tempSheet 
     tell application "System Events" 
      -- deselect all 
      keystroke "a" using {command down, shift down} 
      delay 0.1 
      -- select all containers (tables, text items, etc.) 
      keystroke "a" using {command down} 
      delay 0.1 
      -- copy the containers 
      keystroke "c" using {command down} 
     end tell 
     delay 0.1 
     set dateString to (month of (current date)) & (day of (current date)) as string 
     set thisSheet to make new sheet with properties {name:dateString} 
     tell thisSheet 
      delete every table 
      tell application "System Events" 
       keystroke "v" using {command down} 
      end tell 
     end tell 
    end tell 
end tell 
+0

今天晚些時候我會測試這樣的東西,但它可能不會真正有用,因爲我有每張表17個表格(全部使用隱藏的單元格)。所以它可能會是一團糟...... – pekapa

+1

不要是這樣的悲觀主義者;你會得到它。 :)我添加了更多的代碼來幫助演示更多。發佈,如果你仍然有問題。 – jweaks

+0

這工作很好! xD 但是,我的模板工作表必須處於活動狀態,如果有任何其他工作表位於前面,那麼該工作表將被複制。 (我認爲'觸摸'破解會解決這個問題,但是沒有。= /) – pekapa