3
votes

As I know: "appendRow(rowContents) add values to the bottom of the spreadsheet But how to add data from the form in multiple rows in top of the spreadsheet?"

Now I am looking for some help to always place the name in the top row of my sheet with '.appendRow'.


Here is some parts the code:

var range = sheet.getRange("A:D");
range.clear(); 
sheet.appendRow (["A", "B", "C", "D"])

The code, data is constantly pulled in row A-D but I want to do some calculation in rows E-H. The problem is that with that code "A", "B", "C", "D" is not placed in the top row of my sheet when I write something f.ex. in Cell E.

Grateful for any advice!

2

2 Answers

2
votes

If I understood your question correctly, you want to use appendRow at the top of the Spreadsheet. If so, there is a workaround for it. First you will need to insert a row at the top of the document, and after that you will be able to put values there. An example code would be:

sheet.insertRowBefore(1);
sheet.getRange(1, 1, 1, 4).setValues(["A", "B", "C", "D"]);

Doing it will push all the existing rows to the bottom while you append a new row at the top. You can learn more about insertRowBefore in its documentation. I hope that this fulfills your question, but don't hesitate to tell me if I mistook your issue, so I can help you better.

1
votes

Try changing

sheet.appendRow (["A", "B", "C", "D"])

to

sheet.getRange(1, 1, 1, 4).setValues([["A", "B", "C", "D"]])

and see if that helps?