简体   繁体   中英

How to create a new row at the end of an existing sheet in Google Spreadsheets after completing a Google Form?

I'm trying to save responses from a linked Google Form into an existing Google sheet. More precisely, the spreadsheet shows employee's time off requests with the employee's Reason for leave, Number of days requested, Date Requested, Name of Manager, etc. Basically, the form asks the employee for these information.
Thanks!

What I'm trying to achieve here is saving the response information into the already created spreadsheet. According to Google's documentation , the only two options are:
1) Create a new spreadsheet: Creates a spreadsheet for responses in Google Sheets
2) Select existing spreadsheet: Choose from your existing spreadsheets in Google Sheets to store responses
In case of option #2, I can save responses in the same spreadsheet BUT it saves them in a new sheet; I'm trying to save the responses in the sheet. 张纸中。

I know that Google Form has a Script Editor. Would it be possible to run a function that sends the responses to the Spreadsheet? Maybe something like this?

function sendToSpreadSheet(e)
{
  var ss = SpreadsheetApp.openById("abc1234567");
  // Send response to spreadsheet

  // Populate cells accordingly
}

I don't have much experience with Google Forms, so I'm not sure how to approach this issue. Any suggestion(s) is greatly appreciated.

Try this:

You have to supply the Spreadsheet Id and SheetName. And also create a onFormSubmit trigger for the spreadsheet.

function saveResponse(e) {
  SpreadsheetApp.getActive().getSheetByName('SheetName').append(e.values);
}

or

function saveResponse(e) {
  SpreadsheetApp.openById('id').getSheetByName('SheetName').append(e.values);
}

You can create trigger with something like this:

function createSetResponseTrigger(){
  createTrigger('setResponse');
}

function createTrigger(funcname) {
  if(!isTrigger(funcname)) {
    ScriptApp.newTrigger(funcname).forSpreadsheet(SpreadsheetApp.getActive()).onFormSubmit().create();
  }
}

and this

function isTrigger(funcName){
  var r=false;
  if(funcName){
    var allTriggers=ScriptApp.getProjectTriggers();
    for(var i=0;i<allTriggers.length;i++){
      if(funcName==allTriggers[i].getHandlerFunction()){
        r=true;
        break;
      }
    }
  }
  return r;
}

or you can just create it manually with Edit Menu/Current Project Triggers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM