Reputation: 31
I have a code to add a array of content in a row but i need to add it in a specific range so the checkboxes in the first column are not read as information, so it can add up the row but in the same row that the checkbox it's in.
function criarRegistro() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("EQUIPAMENTOS NO LABORATÓRIO");
var destinyLog = ss.getSheetByName("EQUIPAMENTOS NO LABORATÓRIO");
sheet.activate();
var source = sheet.getRange("C2:G2");
var rangeLimpeza = sheet.getRange("C2:G2");
var values = source.getValues();
//rangeLimpeza.clearContent();
destinyLog.appendRow(values[0]);
ss.toast("Registro finalizado");
SpreadsheetApp.flush();
}
That's the code i'm using, basically i want to appendRow or copy the row information starting in B column, while in the A column i would have a preset of unmarked checkboxes.
Upvotes: 0
Views: 631
Reputation: 2314
You cannot use appendRow
but you can calculate the correct destination range where the values should be copied and then use a basic getRange().setValues()
.
Rewriting and cleaning your function
function criarRegistro() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("EQUIPAMENTOS NO LABORATÓRIO");
var destinyLog = ss.getSheetByName("EQUIPAMENTOS NO LABORATÓRIO");
var source = sheet.getRange("C2:G2");
var values = source.getValues();
var nbOfCols = values[0].length; // how many columns do we need
var lastLineOfData = destinyLog.getDataRange().getNumRows() // how many rows are already present in the destination
destinyLog.getRange(lastLineOfData+1, 2, 1, nbOfCols).setValues(values) // we write after the last line, starting at the second column (B)
ss.toast("Registro finalizado");
SpreadsheetApp.flush();
}
Upvotes: 1