Google apps appendrow script at the top

As I know

appendRow (rowContents) add values ​​to the bottom of the table But how to add data from the form to several rows at the top of the table?

So, if in the form I have lines

  • first, last name, first name
  • second, last name, first name
  • third, last name, first name

in the sheet it should be placed like, and each time in the top

so if another form time will be

  1. fourth, last name, first name
  2. fifth, last name, first name
  3. six, last name, first name

data will be added, for example

enter image description here

Now I use this code, but it adds all the data to the end and works with only one line, I think I should quote all the lines in the form, but how to do it?

function getValuesFromForm(form){
  var firstName = form.firstName,
      lastName = form.lastName,
      order = form.order,
      sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  sheet.appendRow([order,lastName,firstName]);
}
+4
1

, . :

function prependRow(sheet, rowData) {
  sheet.insertRowBefore(1).getRange(1, 1, 1, rowData.length).setValues([rowData]);
}

, , , .

function insertRow(sheet, rowData, optIndex) {
  var index = optIndex || 1;
  sheet.insertRowBefore(index).getRange(index, 1, 1, rowData.length).setValues([rowData]);
}

appendRow , . , . , lock , :

function insertRow(sheet, rowData, optIndex) {
  var lock = LockService.getScriptLock();
  lock.waitLock(30000);
  try { 
    var index = optIndex || 1;
    sheet.insertRowBefore(index).getRange(index, 1, 1, rowData.length).setValues([rowData]);
    SpreadsheetApp.flush();
  } finally {
    lock.releaseLock();
  }
}

, , ..

function getValuesFromForm(form){
  //...
  insertRow(sheet, [order,lastName,firstName]); //could have passed an extra `2` parameter to skip a one line header
}
+12

All Articles