Skip to content

Instantly share code, notes, and snippets.

@Slowhand0309
Last active August 29, 2015 14:26
Show Gist options
  • Save Slowhand0309/d50423bf92f69d80e298 to your computer and use it in GitHub Desktop.
Save Slowhand0309/d50423bf92f69d80e298 to your computer and use it in GitHub Desktop.
Google Apps Script Form SetDestination
/**
* スプレットシートとフォームの結び付け
*/
function bindForm() {
// フォーム取得
var formUrl = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var form = FormApp.openByUrl(formUrl);
// スプレットシート取得
var ss = SpreadsheetApp.getActiveSpreadsheet();
form.setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
var date = new Date();
var sheetName = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate();
// シート名を変更
var sheets = ss.getSheets();
for (var i = 0; i < sheets.length; i++) {
// シート名に「フォームの回答」が含まれている場合
var name = sheets[i].getName();
if (name.indexOf('フォームの回答') != -1
&& name.indexOf(sheetName) == -1) {
sheets[i].setName(sheetName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment