如何使用Apple脚本在excel中设置常量系列值

时间:2012-10-29 03:38:11

标签: excel applescript

如何使用apple脚本在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

1 个答案:

答案 0 :(得分:0)

我不确定我的语法是否错误或是否是错误。

Series

您可以使用以下方法创建一个包含常量的新系列:

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

Chart