Reputation: 19
Pls help me to understand what happening. I have code
function splitWords() {
var list = SpreadsheetApp.getActiveSheet();
var list_Key = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Keys');
if (list.getName() !== list_Key.getName()) {
SpreadsheetApp.getUi().alert('Для работы функции перейдите на страницу Keys');
} else {
var array = list.getRange('C2:C').getValues();
var t_array = array.filter(String).lenght;
SpreadsheetApp.getUi().alert(array);
var array1 = array.reduce(function (s, c) {
var key = c[0];
var keys = key.split(" ");
for (var i in keys) {
if (!s.includes(keys[i])) {
s.push(keys[i])
}
}
return s;
}, []);
SpreadsheetApp.getUi().alert(array1);
SpreadsheetApp.getActive().getActiveSheet().getRange(2,8,array1.length,array1[0].length).setValues(array1);
}
}
When code comes to setValues()
i have error.
The parameters (number[]) don't match the method signature for SpreadsheetApp.Range.setValues
Upvotes: 1
Views: 3566
Reputation: 201378
In your script, array1
is 1 dimensional array. But it is required to be 2 dimensional array for serValues
. I think that this is the reason of your issue. When you want to put the values of array1
to the range from "H2" to the row direction, it is required to include each element of array1
in an array. So how about the following modification?
s.push(keys[i])
s.push([keys[i]]);
you want to put the values of array1
to the range from "H2" to the column direction, how about the following modification?
From:
SpreadsheetApp.getActive().getActiveSheet().getRange(2,8,array1.length,array1[0].length).setValues(array1);
To:
array1 = [array1];
SpreadsheetApp.getActive().getActiveSheet().getRange(2,8,array1.length,array1[0].length).setValues(array1);
Upvotes: 1