1

如何使用苹果脚本在excel中设置常数系列值。

 tell worksheet 1 of active workbook
      set obj to make new chart object at end with properties{ 
                                     left position:120,top:50,width: 120,height:150}  
 set ochart to chart of obj    
      tell ochart
           make new series at end with properties {series values:"={1}"}
      end tell
 end tell

 This script through error(Microsoft Excel got an error:Can't make class series)

Please replay
4

1 回答 1

0

我不确定我的语法是否错误或者这是一个错误。

系列

您希望能够使用以下方法创建具有常量的新系列:

set newSeries to make new series at end with properties {name:"tempSeriesName", series values:{50}}

但是,我只能使用一个范围来创建系列:

set newSeries to make new series at end with properties {name:"tempSeriesName", series values:"A2"}

但是,创建系列后,您可以使用以下命令更新值:

set series values to {50}

我的解决方法是在 A 列中找到第一个空白单元格并用一个值填充它。然后我使用此单元格创建范围,使用常量更新范围,然后将临时单元格恢复为空白。

tell application "Microsoft Excel"
    tell worksheet "Sheet1" of active workbook
        -- Find the first empty cell and populate it with 1
        set counter to 0
        repeat
            set counter to counter + 1
            set myRange to ("A" & counter as text)
            if value of range myRange = "" then
                set value of range myRange to "1"
                exit repeat
            end if
        end repeat

        set obj to make new chart object at end with properties {name:"chart1", left position:20, top:88, width:33, height:90}
        set ochart to chart of obj
        tell ochart
            set chart type to column clustered
            -- create the chart with the temporary value
            set newSeries to make new series at end with properties {name:"tempSeriesName", series values:myRange}
            -- update the chart with your constant value
            set series values of newSeries to {50}
        end tell
        set value of range myRange to ""
    end tell
end tell

图表

于 2012-11-07T20:56:20.993 回答