Create a new sheet in an existing spreadsheet for EACH RESPONSE from a Google Form

一曲冷凌霜 提交于 2019-12-10 11:57:24

问题


I have created a Google form, and I need to create a new sheet in an existing spreadsheet for each response I receive from this form - each respondent generates a new sheet within the spreadsheet. Is this possible with some kind of onSubmit command? I'm completely new to Javascript but willing to learn. Thanks so much for your help.


回答1:


You can't intercept a Google Form submission before the data is written into the spreadsheet. All you can do is manipulate the data after it's already been inserted into the spreadsheet. So, your responses will get put into the spreadsheet, all in one sheet to start with. You can't change that.

Now the question is, do you want to manipulate the data from code bound to the form or bound to the sheet? You'll want to use a project bound to the sheet.

This is some sample code:

This code assumes that the value you want to name your sheet is in column A function subTheForm() { Logger.log('submit ran');

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  //Get last row of data
  var lastRow = sheet.getLastRow();
  var colA_Data = sheet.getRange(lastRow, 1).getValue();

  //var thisUser = 'theUserName';
  ss.insertSheet(colA_Data);
};

Old answer:

You'll need to generate some kind of unique string every time a new form is submitted. I have no idea what you want. You could get the user name, then add the date/time to it, then name each new sheet the user name with the time. The basic code will look like this:

function submit(){
  Logger.log('submit ran');

  var thisUser = 'theUserName';
  var ss = SpreadsheetApp.getActive().insertSheet(thisUser);

};

Note the Logger.log(); statement. That prints something to the LOG. Inside the code editor, you can select the VIEW menu, and the LOGS menu item to show the LOG.

You can also run the code "manually" from the code editor by selecting the function name and clicking the run arrow icon. That way you can run the code without submitting a form every time. Get the code to work, then wire it up to the onsubmit trigger.




回答2:


For this you can get the Spreadsheet using this command(getActiveSpreadsheet()) and then create a new sheet based on the parameters you require from this page. you can add this lines of code in your onSubmit trigger.

Hope that helps!



来源:https://stackoverflow.com/questions/28305238/create-a-new-sheet-in-an-existing-spreadsheet-for-each-response-from-a-google-fo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!