在excel 2011中,使用Apple脚本创建了一个额外系列。
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
我的问题是,在sheet1中创建了一个额外的系列(即系列1)。
答案 0 :(得分: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
答案 1 :(得分: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
注意 - 我单独创建了这个系列,因为我无法弄清楚如何在一个语句中为每个系列提供一个名称。