// ①スプレッドシートの取得
function getForm1() {
const ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/###");
const sheet = ss.getSheetByName('シート#');
return sheet
// done!!!!
}
// ②googleフォームの取得
function openGoogleform() {
const gf = FormApp.openByUrl("https://docs.google.com/forms/###");
return gf
}
// ③データのセット(初期)
function initialDate() {
const sheet = getForm1();
sheet.getRange(2,4).setValue("11:00~11:30")
sheet.getRange(3,4).setValue("11:30~12:00")
sheet.getRange(4,4).setValue("12:00~12:30")
sheet.getRange(5,4).setValue("12:30~13:00")
sheet.getRange(6,4).setValue("13:00~13:30")
sheet.getRange(7,4).setValue("13:30~14:00")
}
function setDate() {
const form = getForm1();
const values = form.getRange(2,4,6).getValues()
console.log(values)
const gf = openGoogleform();
const itemId = ####;// itemのID
const choices = gf.getItemById(itemId).asMultipleChoiceItem();
choices.setChoiceValues(values);
}
// ④googleフォームの回答を取得
function receveinform() {
const gf = openGoogleform();
// length = 回答数
const length = gf.getResponses().length;
const sheet = getForm1();
// セルの値を取得→それがどの選択肢に当てはまるか確認→
// 時間の選択肢の集合
const first = "11:00~11:30";
const second = "11:30~12:00";
const third = "12:00~12:30";
const fourth = "12:30~13:00";
const fifth = "13:00~13:30";
const sixth = "13:30~14:00";
// 人数制限の集合
const reg = 2;
let a = 0;
let b = 0;
let c = 0;
let d = 0;
let e = 0;
let f = 0;
for(let i = 3; i<=length+2;i++){
const value = sheet.getRange(i,2).getValue();
if(value == first){
a++;
}else if(value==second){
b++;
}else if(value==third){
c++;
}else if(value==fourth){
d++;
}else if(value==fifth){
e++
}else if(value==sixth){
f++
}
}
if(a>=reg){
const form = getForm2();
if(form.getRange(2,4).getValue()==first){
form.deleteRow(2)
}else{
for(let i = 2;i<6;i++){
let value = form.getRange(i,4).getValue();
if(value==first){
form.deleteRow(i);
}
}
}
}else if(b>=reg){
const form = getForm2();
if(form.getRange(3,4).getValue()==first){
form.deleteRow(3)
}else{
for(let i = 2;i<6;i++){
let value = form.getRange(i,4).getValue();
if(value==second){
form.deleteRow(i);
}
}
}
}else if(c>=reg){
const form = getForm2();
if(form.getRange(4,4).getValue()==first){
form.deleteRow(4)
}else{
for(let i = 2;i<6;i++){
let value = form.getRange(i,4).getValue();
if(value==third){
form.deleteRow(i);
}
}
}
}else if(d>=reg){
const form = getForm2();
if(form.getRange(5,4).getValue()==first){
form.deleteRow(5)
}else{
for(let i = 2;i<6;i++){
let value = form.getRange(i,4).getValue();
if(value==fourth){
form.deleteRow(i);
}
}
}
}else if(e>=reg){
const form = getForm2();
if(form.getRange(6,4).getValue()==first){
form.deleteRow(6)
}else{
for(let i = 2;i<6;i++){
let value = form.getRange(i,4).getValue();
if(value==fifth){
form.deleteRow(i);
}
}
}
}else if(f>=reg){
const form = getForm2();
if(form.getRange(7,4).getValue()==first){
form.deleteRow(7)
}else{
for(let i = 2;i<6;i++){
let value = form.getRange(i,4).getValue();
if(value==sixth){
form.deleteRow(i);
}
}
}
}
}
// ⑤人数の確認
function checkNumber() {
const form = getForm2();
console.log(form.getRange(2,4).getValue() == "11:00~11:30");
console.log(form.getRange(2,4).getValue());
}