2013-02-07 27 views
0

在Excel 2011中,使用apple腳本創建了一個額外的系列。Excel 2011中的圖表中創建了一個額外的系列

tell application "Microsoft Excel" 
    make new workbook 
    tell worksheet "sheet1" of active workbook 
     set value of cell "A1" to 10 
     set value of cell "B1" to 5 
     set obj to make new chart object at end with properties {left position:100,  top:100, height:200, width:300, name:"MyChart"} 
     set ochart1 to chart of chart object "MyChart" 
     tell ochart1 
      set chart type to bar clustered 
      make new series at end with properties {series values:"=Sheet1!$A$1:$B$1", name:"2"} 

     end tell 
    end tell 
end tell 

我的問題,一個額外的系列(即系列1)在sheet1中創建。

enter image description here

enter image description here

+0

新圖表創建時通常會有一個系列,因此您需要在添加新系列之前刪除所有現有系列 –

+0

請運行我的腳本,一次創建兩個系列。 – user1705318

+0

如果此語句以屬性{系列值:「= Sheet1!$ A $ 1:$ C $ 1」,名稱:「2」}創建新系列,則創建三個系列,即創建兩個系列。 – user1705318

回答

0

我敢肯定這是不是這樣做的正確的方式,但它應該完成這項工作。

tell application "Microsoft Excel" 
    make new workbook 
    tell worksheet "sheet1" of active workbook 
     set value of cell "A1" to 10 
     set value of cell "B1" to 5 
     set obj to make new chart object at end with properties {left position:100, top:100, height:200, width:300, name:"MyChart"} 
     set ochart1 to chart of chart object "MyChart" 
     tell ochart1 
      set chart type to bar clustered 
      make new series at end with properties {series values:"=Sheet1!$A$1:$B$1", name:"2"} 
      delete (every series whose name ≠ "2") 
     end tell 
    end tell 
end tell 
+0

如果此語句在屬性{系列值:「= Sheet1!$ A $ 1:$ C $ 1」}的末尾創建新系列,則創建三個系列,即兩個系列是額外創建的。我的問題是,我的腳本已成功運行案例列到行。但在將列增加到列的情況下,我的腳本失敗。如果我的單元格範圍是A1到C1,則創建3個系列,如果範圍是A1到D1,則創建4個系列。 – user1705318

+0

如果我運行包含兩個make系列語句的腳本。首先是 - >以屬性{系列值:「= Sheet1!$ A $ 1:$ B $ 1」}結束新系列,第二個是以屬性{系列值:「= Sheet1!$ A $ 1: $ c $ 1「}。如果創建了5個系列,即3個系列是額外創建的。我怎麼能識別3系列被刪除。 – user1705318

+0

查看第二個屏幕截圖附有5個系列,如果三系列系列1,系列3,系列4是額外創建的,如何識別系列1系列3和系列4被刪除。 – user1705318

0

看來,當你創建一個更有意義的一系列事情做工精細:

tell application "Microsoft Excel" 
    make new workbook 
    tell worksheet "sheet1" of active workbook 
     set value of cell "A1" to 2 
     set value of cell "B1" to 3 
     set value of cell "A2" to 4 
     set value of cell "B2" to 6 
     set value of cell "A3" to 10 
     set value of cell "B3" to 5 
     set obj to make new chart object at end with properties {left position:100, top:100, height:200, width:300, name:"MyChart"} 
     set ochart1 to chart of chart object "MyChart" 
     tell ochart1 
      set chart type to bar clustered 
      #remove first series 
      make new series at end with properties {series values:"=Sheet1!$A$1:$A$3", name:"one"} 
      make new series at end with properties {series values:"=Sheet1!$B$1:$B$3", name:"two"} 
     end tell 
    end tell 
end tell 

注 - 我創造了一系列分開,因爲我無法弄清楚如何讓他們在每一個名字一個單一的陳述。

+0

如果系列範圍是= Sheet1!$ A $ 1:$ C $ 1,則額外創建兩個系列。 – user1705318

相關問題