Share
Embed
Google Form とちょっと 仲良くなった話。
Google Apps Script LT会! で登壇した内容です。
https://yumenosora.connpass.com/event/265341/
4geru
December 05, 2022
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
45 slides
-
ࣗݾհ Name: ͛͠Δ Twitter: @_4geru Github, Zenn: @4geru Primary Language:
Ruby♥♥ Interest: QA, Flutter Work: Money Forward Live: Tokyo, From: Shiga Hobby: Diving 🤿, Camera 📸, Aquarium 🐟 Current News: ΠϯϑϧΤϯβͷϫΫν ϯଧͪ·ͨ͠ -
LGTMʹ͍ͭͯ ϚωʔϑΥϫʔυValueͷ̍ͭʹɺ ςΫϊϩδʔυϦϒϯ Λܝ͍͛ͯ·͢ɻ ςΫϊ ϩδʔυϦϒϯ ͕ৗʹମݱ͞ΕɺจԽͱ͍͍ͯࠜͯ͠ΔձࣾΛࢦ͍ͯ͠·͢ɻ ձ ࣾͷจԽɺʑͷ׆ಈͷ݁Ռৢ͞Εͯ͘Δͷͩͱࢥ͍·͢͠ɺ ςΫϊϩδʔυϦ
ϒϯͳจԽ Λ࡞ΕΔ͔Ͳ͏͔ɺʑͷΤϯδχΞͷ׆ಈͷ݁Ռ࣍ୈͩͱࢥ͍·͢ɻ LGTMΛͬͯΈΑ͏ͱࢥͬͨͷɺςΫϊϩδʔυϦϒϯ ͩͱײ͡Δ׆ಈΛΈΜͳ ʹਪનͯ͠Β͏͜ͱͰɺMFͷΤϯδχΞ͕ཧͱ͢Δ ςΫϊϩδʔυϦϒϯ ͷղ૾ Λ্͛ɺจԽͱͯࠜͨ͘͠Ίͷ͕͔Γʹͯ͠΄͍͠ɺͱ͍͏ࢥ͍͔ΒͰ͢ɻ -
LGTMͷӡ༻ʹ͍ͭͯ(before) • υΩϡϝϯτπʔϧʹՕॻ͖Ͱืू • ٕज़ใ͕ Google Form ʹసه • Թ͔Έͷ͋Δӡ༻Ͱɺຖճ͕͔͔͍࣌ؒͬͯ·ͨ͠ɻ
• ίϐϖͷϛεͳ͍͔֬ೝ͢Δ࡞ۀൃੜ • ਓͷख࡞ۀ -
LGTMͷӡ༻ʹ͍ͭͯ(after) • υΩϡϝϯτπʔϧʹՕॻ͖Ͱืू • Google Sheets ʹΠϯϙʔτ • Google Sheets
Ͱจݴमਖ਼ • Google Form ʹΤΫεϙʔτ • DeepL Λͬͯӳޠʹಉ࣌༁ • ਓͷख࡞ۀ after Ͱɺసه࡞ۀ͕ͳ͘ͳΓɺ֬ೝ࡞ۀΛ͢Δ͚ͩ + ӳޠͷ༁͖ͭ·ͨ͠ -
LGTMͷӡ༻ʹ͍ͭͯ(after) • υΩϡϝϯτπʔϧʹՕॻ͖Ͱืू • Google Sheets ʹΠϯϙʔτ • Google Sheets
Ͱจݴमਖ਼ • Google Form ʹΤΫεϙʔτ • DeepL Λͬͯӳޠʹಉ࣌༁ • ਓͷख࡞ۀ after Ͱɺసه࡞ۀ͕ͳ͘ͳΓɺ֬ೝ࡞ۀΛ͢Δ͚ͩ + ӳޠͷ༁͖ͭ·ͨ͠ ࠓճ͢ͷίίʂ ίίʂҎ֎ zenn Λݟ͍ͯͩ͘͞ -
https://developers.google.com/apps-script/reference/forms αϯϓϧίʔυ͕ॆ࣮͍ͯ͠Δʂ // Create a new form, then add a
checkbox question, a multiple choice question, // a page break, then a date question and a grid of questions. var form = FormApp.create('New Form'); var item = form.addCheckboxItem(); item.setTitle('What condiments would you like on your hot dog?'); item.setChoices([ item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish') ]); form.addMultipleChoiceItem() .setTitle('Do you prefer cats or dogs?') .setChoiceValues(['Cats','Dogs']) .showOtherOption(true); form.addPageBreakItem() .setTitle('Getting to know you'); form.addDateItem() .setTitle('When were you born?'); form.addGridItem() .setTitle('Rate your interests') .setRows(['Cars', 'Computers', 'Celebrities']) .setColumns(['Boring', 'So-so', 'Interesting']); Logger.log('Published URL: ' + form.getPublishedUrl()); Logger.log('Editor URL: ' + form.getEditUrl()); -
͍ͬͯΔؔ ݴޠબϖʔδ ຊޠϖʔδ ӳޠϖʔδ 1. ϖʔδભҠ 2. ϥδΦϘλϯ 3. νΣοΫϘοΫε
3. νΣοΫϘοΫε 4.ஈམ 4.ஈམ 3. νΣοΫϘοΫε 3. νΣοΫϘοΫε -
https://developers.google.com/apps-script/reference/forms/page-break-item Sample code1. ϖʔδભҠ // Create a form and add
three page-break items. var form = FormApp.create('Form Name'); var pageTwo = form.addPageBreakItem().setTitle('Page Two'); var pageThree = form.addPageBreakItem().setTitle('Page Three'); // Make the first two pages navigate elsewhere upon completion. // At end of page one (start of page two), jump to page three pageTwo.setGoToPage(pageThree); // At end of page two, restart form pageThree.setGoToPage(FormApp.PageNavigationType.RESTART); -
https://developers.google.com/apps-script/reference/forms/page-break-item Sample code1. ϖʔδભҠ // Create a form and add
three page-break items. var form = FormApp.create('Form Name'); var pageTwo = form.addPageBreakItem().setTitle('Page Two'); var pageThree = form.addPageBreakItem().setTitle('Page Three'); // Make the first two pages navigate elsewhere upon completion. // At end of page one (start of page two), jump to page three pageTwo.setGoToPage(pageThree); // At end of page two, restart form pageThree.setGoToPage(FormApp.PageNavigationType.RESTART); Form ͷ࡞ -
https://developers.google.com/apps-script/reference/forms/page-break-item Sample code1. ϖʔδભҠ // Create a form and add
three page-break items. var form = FormApp.create('Form Name'); var pageTwo = form.addPageBreakItem().setTitle('Page Two'); var pageThree = form.addPageBreakItem().setTitle('Page Three'); // Make the first two pages navigate elsewhere upon completion. // At end of page one (start of page two), jump to page three pageTwo.setGoToPage(pageThree); // At end of page two, restart form pageThree.setGoToPage(FormApp.PageNavigationType.RESTART); ϖʔδͷࢦఆ ϖʔδͷϦϯΫઃఆ -
https://developers.google.com/apps-script/reference/forms/checkbox-item Sample code 2. ϥδΦϘλϯ // Open a form by
ID and add a new checkbox item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addCheckboxItem(); item.setTitle('What condiments would you like on your hot dog?') .setChoices([ item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish') ]) .showOtherOption(true); -
https://developers.google.com/apps-script/reference/forms/checkbox-item Sample code 2. ϥδΦϘλϯ // Open a form by
ID and add a new checkbox item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addCheckboxItem(); item.setTitle('What condiments would you like on your hot dog?') .setChoices([ item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish') ]) .showOtherOption(true); Form ͷಡΈࠐΈ -
https://developers.google.com/apps-script/reference/forms/checkbox-item Sample code 2. ϥδΦϘλϯ // Open a form by
ID and add a new checkbox item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addCheckboxItem(); item.setTitle('What condiments would you like on your hot dog?') .setChoices([ item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish') ]) .showOtherOption(true); Item ͷઃఆ -
https://developers.google.com/apps-script/reference/forms/checkbox-item Sample code 2. ϥδΦϘλϯ // Open a form by
ID and add a new checkbox item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addCheckboxItem(); item.setTitle('What condiments would you like on your hot dog?') .setChoices([ item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish') ]) .showOtherOption(true); બࢶͷදࣔ -
https://developers.google.com/apps-script/reference/forms/multiple-choice-item Sample code 3. νΣοΫϘοΫε // Open a form by
ID and add a new multiple choice item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addMultipleChoiceItem(); item.setTitle('Do you prefer cats or dogs?') .setChoices([ item.createChoice('Cats'), item.createChoice('Dogs') ]) .showOtherOption(true); -
https://developers.google.com/apps-script/reference/forms/multiple-choice-item Sample code 3. νΣοΫϘοΫε // Open a form by
ID and add a new multiple choice item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addMultipleChoiceItem(); item.setTitle('Do you prefer cats or dogs?') .setChoices([ item.createChoice('Cats'), item.createChoice('Dogs') ]) .showOtherOption(true); Form ͷಡΈࠐΈ -
https://developers.google.com/apps-script/reference/forms/multiple-choice-item Sample code 3. νΣοΫϘοΫε // Open a form by
ID and add a new multiple choice item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addMultipleChoiceItem(); item.setTitle('Do you prefer cats or dogs?') .setChoices([ item.createChoice('Cats'), item.createChoice('Dogs') ]) .showOtherOption(true); Item ͷઃఆ -
https://developers.google.com/apps-script/reference/forms/multiple-choice-item Sample code 3. νΣοΫϘοΫε // Open a form by
ID and add a new multiple choice item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addMultipleChoiceItem(); item.setTitle('Do you prefer cats or dogs?') .setChoices([ item.createChoice('Cats'), item.createChoice('Dogs') ]) .showOtherOption(true); બࢶͷදࣔ -
https://developers.google.com/apps-script/reference/forms/paragraph-text-item Sample code 4. ஈམ // Open a form by
ID and add a new paragraph text item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addParagraphTextItem(); item.setTitle('What is your address?'); -
https://developers.google.com/apps-script/reference/forms/paragraph-text-item Sample code 4. ஈམ // Open a form by
ID and add a new paragraph text item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addParagraphTextItem(); item.setTitle('What is your address?'); Form ͷಡΈࠐΈ -
https://developers.google.com/apps-script/reference/forms/paragraph-text-item Sample code 4. ஈམ // Open a form by
ID and add a new paragraph text item. var form = FormApp.openById('1234567890abcdefghijklmnopqrstuvwxyz'); var item = form.addParagraphTextItem(); item.setTitle('What is your address?'); Item ͷઃఆ -
ݴޠબϖʔδ const separatedExportGooleForm = () => { const form =
FormApp.create(separatedGoogleFormTitle()) .setDescription(formDescription); let item = form.addMultipleChoiceItem(); item.setTitle('ݴޠΛબ͍ͯͩ͘͠͞ɻ / Please select your language.') item.setChoices([ item.createChoice('ຊޠ / Japanese', separatedJapaneseForm(form)), item.createChoice('ӳޠ / English', separatedEnglishForm(form)), ]); return { publishedUrl: form.getPublishedUrl(), editUrl: form.getEditUrl() } } νΣοΫϘοΫεͷ αϯϓϧΛҾ༻͠ ݴޠબͷग़͠Θ͚ Λ͠·͢ ϖʔδભҠ બઌ ͷؔͰࢦఆ͠·͢ɻ -
ຊޠϖʔδ const separatedJapaneseForm = (form) => { let japanesePage =
form.addPageBreakItem().setTitle('ຊޠ'); const spreadSheetHash = separatedFetchSpreadSheetHash(); for (let key in spreadSheetHash) { let item = form.addCheckboxItem(); item.setTitle(key); const choices = spreadSheetHash[key].map((row) => { return item.createChoice(row[1] + row[2]) }) item.setChoices(choices); } form.addParagraphTextItem() .setTitle('ྭ·͠ɾਪનϝοηʔδɾͦͷଞ͝ҙݟײͳͲͳΜͰࣗ༝هೖཝ') japanesePage.setGoToPage(FormApp.PageNavigationType.SUBMIT) return japanesePage } νΣοΫϘοΫε ஈམɺϖʔδભҠͷ αϯϓϧΛҾ༻͠·͢ Spread Sheets ͔ΒFetch ͠ɺΧςΰϦʔ͝ͱʹ બࢶΛग़͍ͯ͠·͢ -
ӳޠϖʔδ const separatedEnglishForm = (form) => { let englishPage =
form.addPageBreakItem().setTitle('English'); const spreadSheetHash = separatedFetchSpreadSheetHash(); for (let key in spreadSheetHash) { let item = form.addCheckboxItem(); item.setTitle(deeplTranslate([key], "JA", "EN")[0].text); const choices = spreadSheetHash[key].map((row) => { const choice = deeplTranslate([row[1] + row[2]], "JA", "EN")[0].text return item.createChoice(choice) }) item.setChoices(choices); } form.addParagraphTextItem() .setTitle('Encouragement, recommendation messages…’) englishPage.setGoToPage(FormApp.PageNavigationType.SUBMIT) return englishPage } ߏຊޠϖʔδͱ ಉ͡ͰɺDeepLͰ༁ Λ͍ͯ͠·͢ɻ ※ ແྉϓϥϯͰ͢ -
LGTMͷӡ༻ʹ͍ͭͯ(after) • υΩϡϝϯτπʔϧʹՕॻ͖Ͱืू • Google Sheets ʹΠϯϙʔτ • Google Sheets
Ͱจݴमਖ਼ • Google Form ʹΤΫεϙʔτ • DeepL Λͬͯӳޠʹಉ࣌༁ • ਓͷख࡞ۀ after Ͱɺసه࡞ۀ͕ͳ͘ͳΓɺ֬ೝ࡞ۀΛ͢Δ͚ͩ + ӳޠͷ༁͖ͭ·ͨ͠ ࠓճ͢ͷίίʂ ίίʂҎ֎ zenn Λݟ͍ͯͩ͘͞ -
ϚωϑΥΞυϕϯτΧϨϯμʔ2022 4 ʹผͷAPI·ͱΊ͍ͯ·͢ɻ ίϐϖ͢Δ͜ͱͰ؆୯ʹಈ͘ͷͰɺͥͻʂ͓खݩͰࢼ͍ͩ͘͠͞ɻ • Google Sheets • Kibela(GraphQL) •
DeepL(RestAPI) • Google Form API Google Apps Script(GAS)Λ͍ͯ͠ɺΞϯέʔτ࡞ΛࣗಈԽͨ͠ https://zenn.dev/4geru/books/advent-calendar-2022-day-4 Zenn ʹ͍ͭͯ