Google フォーム スプレッドシートから PDF に結合する Google スクリプトがあります。Google Apps スクリプトで、チェックボックスがマークされているかどうかを確認し、フォームを複製することは可能ですか?
質問
選択肢 1
選択肢 2
選択肢 3
基本的に、ここで機能します。ユーザーが Google フォームに入力するすべてのキーを持つ Google Doc テンプレートがあります。スクリプトはスプレッドシートとテンプレートを参照します。
ここに私が持っている作業コードがあります:
//Get template and name it
var docTemplate = "id";
var docName = "name";
//Reference Spreadsheet
function getColIndexByName(colName) {
var sheet = SpreadsheetApp.getActiveSheet();
var numColumns = sheet.getLastColumn();
var row = sheet.getRange(1, 1, 1, numColumns).getValues();
for (i in row[0]) {
var name = row[0][i];
if (name == colName) {
return parseInt(i) + 1;
}
}
return -1;
}
//Form submittal
function onFormSubmit() {
//spreadsheet values
var sheet = SpreadsheetApp.getActiveSheet();
var row = sheet.getActiveRange().getRowIndex();
var email = sheet.getRange(row, getColIndexByName("E-mail:")).getValue();
var title = sheet.getRange(row, getColIndexByName("Title of Proposed Request (problem / opportunity):")).getValue();
var school = sheet.getRange(row, getColIndexByName("School")).getValue();
var office = sheet.getRange(row, getColIndexByName("Office")).getValue();
var facproblems =sheet.getRange(row, getColIndexByName("Which of the following best describes the facilities-related problem (or opportunity) your School/Office has identified?")).getValue();
var uses = sheet.getRange(row, getColIndexByName("Please list what other uses / functions need to be adjacent to your program/activity.")).getValue();
var describeProblem = sheet.getRange(row, getColIndexByName("a) Describe the identified problem or opportunity.")).getValue();
var impacts = sheet.getRange(row, getColIndexByName("b) Part I: Provide justification and evidence in support of the identified problem/opportunity. Impacts - select one or more from the below list.")).getValue();
var impactsExplain = sheet.getRange(row, getColIndexByName("b) Part II: Provide justification and evidence in support of the identified problem/opportunity. Explain how the proposed project will achieve the impacts you indicated above.")).getValue();
var advance = sheet.getRange(row, getColIndexByName("c) Explain how the requested project will advance the College’s Strategic Plan and/or the requesting school or office’s academic plan and / or business plan.")).getValue();
var estimate = sheet.getRange(row, getColIndexByName("d) Part I: What is your estimate of the potential cost (in rough order of magnitude) of addressing the problem or opportunity described above? ")).getValue();
var estimateExplain = sheet.getRange(row, getColIndexByName("d) Part II: Please explain how your developed this estimate.")).getValue();
var requestor = sheet.getRange(row, getColIndexByName("Name of Requestor/Proposer")).getValue();
var date = sheet.getRange(row, getColIndexByName("Date")).getValue();
var title = sheet.getRange(row, getColIndexByName("Title of Proposed Request (problem / opportunity):")).getValue();
var phone = sheet.getRange(row, getColIndexByName("Phone No.")).getValue();
var sponsor = sheet.getRange(row, getColIndexByName("Name of Project Sponsor")).getValue();
//copy and combine doc name and name form
var copyId = DocsList.getFileById(docTemplate)
.makeCopy(docName+' for '+requestor)
.getId();
//open temp doc and copy body
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
//replace placeholderkeys from template
copyBody.replaceText('keyProposedTitle', title);
copyBody.replaceText('keySchool', school);
copyBody.replaceText('keyOffice', office);
copyBody.replaceText('keyFacProblem', facproblems);
copyBody.replaceText('keyUses', uses);
copyBody.replaceText('keyDescribeProblem', describeProblem);
copyBody.replaceText('keyImpacts', impacts);
copyBody.replaceText('keyImpactsExplain', impactsExplain);
copyBody.replaceText('keyAdvance', advance);
copyBody.replaceText('keyEstimate', estimate);
copyBody.replaceText('keyEstimateExplain', estimateExplain);
copyBody.replaceText('keyRequestor', requestor);
copyBody.replaceText('keyDate', date);
copyBody.replaceText('keyPhone', phone);
copyBody.replaceText('keyEmail', email);
copyBody.replaceText('keySponsor', sponsor);
//save and close doc
copyDoc.saveAndClose();
//create PDF of temp doc
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
//email recipient
var subject = "Manhattan College Space Planning Form Submittal";
var body = "Thanks for submitting your request. \n\nPlease find an attachment with the details given."
MailApp.sendEmail(email, subject, body, {htmlBody: body, attachments: pdf});
//trash temp doc
DocsList.getFileById(copyId).setTrashed(true);
}
助けてくれてありがとう。