可以在范围内转换数组吗?

时间:2018-07-16 13:14:36

标签: javascript google-apps-script google-sheets

我正在尝试绘制图表,但无法转换范围内的数组:

function extrair() {
    var dataSourceUrl = SpreadsheetApp.getActiveSheet();
    var ergonomia = dataSourceUrl.getRange(3,2,4,1).getValues();//B3:B6
    var chartBuilder = dataSourceUrl.newChart()
        .setChartType(Charts.ChartType.BAR)
        .addRange(ergonomia)
        .setPosition(5, 5, 0, 0)
        .build();
}

1 个答案:

答案 0 :(得分:0)

由于您首先获得了范围,然后才得到数组,所以不需要进行这种转换。只要确保首先存储范围,并引入一个变量即可:

function extrair() {
    var dataSourceUrl = SpreadsheetApp.getActiveSheet();
    var ergonomiaRange = dataSourceUrl.getRange(3,2,4,1); //B3:B6
    var ergonomia = ergonomiaRange.getValues(); //the array (which is not used in this code)
    var chartBuilder = dataSourceUrl.newChart()
        .setChartType(Charts.ChartType.BAR)
        .addRange(ergonomiaRange)
        .setPosition(5, 5, 0, 0)
        .build();
}