Skip to content Skip to sidebar Skip to footer

Inserting Data Into Different Sheets In Google Sheet

I try create in google sheet form to inserting data into several sheets at once. When you open the form you have field for entering some values and Checkbox where you can select a

Solution 1:

How about following modification?

In order to retrieve values from input, it uses this.parentNode for formSubmit(). By this, at getValuesFromForm(form), NrItem can be retrieved by form.NrItem.

Modified script :

This is the modification for the HTML file.

.
.
.
  <inputonclick="formSubmit(this.parentNode)"type="button"value="Add Row" /><inputonclick="google.script.host.close()"type="button"value="Exit" /></form><scripttype="text/javascript">functionformSubmit(e) {
    google.script.run.getValuesFromForm(e);
  }
</script>

Note :

When sampletext was inputted to the text box and the checkboxes of sheet1 and sheet2 are checked, this.parentNode becomes

{"NrItem":"sampletext","choices":["something1","something2"]}

If I misunderstand your question, I'm sorry.


Edit

If the sheet names of Sheet1, Sheet2 and Sheet3 are constant, you can use following sample.

Modified HTML :

<br><inputname="choices"type="checkbox"value="Sheet1" /> sheet1
<br><br><inputname="choices"type="checkbox"value="Sheet2" /> sheet2
<br><br><inputname="choices"type="checkbox"value="Sheet3" /> sheet3
<br>

Modified GAS :

varNrItem = form.NrItem,
    date = Utilities.formatDate(newDate(), "GMT", "yyyy-MM-dd");
    sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets();
for (var i in sheets) {
  for (var j in form.choices) {
    if (form.choices[j] == sheets[i].getName()) {
      sheets[i].appendRow([date, NrItem]);
    }
  }
}

If this was not the sample you want, feel free to tell me.

Post a Comment for "Inserting Data Into Different Sheets In Google Sheet"