0

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); 


}

助けてくれてありがとう。

4

1 に答える 1

1

私はそれを考え出した。

Google フォーム スプレッドシートで次のことを行いました。

  1. オプションをスプレッドシートの異なる列に分けました。
  2. 数式を使用 = ArrayFormula(IFERROR(SIGN(FIND(F$1;$E2:$E))))
    F$1は、選択が列 F 行 1にあるため、この場合に使用されます。
    列 Eは、質問があった元の列です。と尋ねられ、応答はRow 2から始まるため、$E2:$Eが使用されます。列に一致するすべての応答に「1」
    を配置します。


コードに変数を追加しました。以下はコード全体です。

//Get template and name it
var docTemplate = "1n9ytnC2bNrkPZ62pNiyi3Xy6GcDRvGPLZRMfJxsLY1g";
var docName = "ManhattanCollegeSpacePlanning";


//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 addSpaceExisting = sheet.getRange(row, getColIndexByName("Additional space is needed for existing projects/programs/activities.")).getValue();
  var addSpaceNew = sheet.getRange(row, getColIndexByName("Additional space is needed for new projects/programs/activities.")).getValue();
  var currentSpace = sheet.getRange(row, getColIndexByName("Current space is substandard or inappropriate")).getValue();
  var relocation = sheet.getRange(row, getColIndexByName("Relocation required for better adjacencies (list what other uses / functions need to be adjacent to your program/activity)")).getValue();
  var displacement = sheet.getRange(row, getColIndexByName("Displacement from existing space – relocation required.")).getValue();
  var other = sheet.getRange(row, getColIndexByName("Other (not described in other categories above).")).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('keyAddSpaceExisting', addSpaceExisting);
  copyBody.replaceText('keyAddSpaceNew', addSpaceNew);
  copyBody.replaceText('keyCurrentSpace', currentSpace);
  copyBody.replaceText('keyRelocation', relocation);
  copyBody.replaceText('keyDisplacement', displacement);
  copyBody.replaceText('keyOther', other);
  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); 


}
于 2013-11-07T16:26:42.547 に答える