简体   繁体   中英

How to partially change a file name in google apps script?

 function autoFillGoogleDocFromForm(e) {




  var timestamp = e.values[0];
  var auditorFirmName = e.values[1];
  var auditorAddressLine1 = e.values [2];
  var auditorAddressLine2 = e.values[3];
  var auditorAddressLine3 = e.values[4];
  var auditorAddressLine4 = e.values [5];
  var dateOfLetterIssue = e.values[6];
  const template = "template";



  var templateFile = DriveApp.getFileById("");
  var templateFolder = DriveApp.getFolderById("");

  var copy = templateFile.makeCopy(auditorFirmName + ${template}, templateFolder);
  var doc = DocumentApp.openById(copy.getId());

  var body = doc.getBody();

  body.replaceText("{{Insert Auditor Firm name}}", auditorFirmName);
  body.replaceText("{{Address Line 1}}", auditorAddressLine1);
  body.replaceText("{{Address Line 2}}", auditorAddressLine2);
  body.replaceText("{{Address Line 3}}", auditorAddressLine3);
  body.replaceText("{{Address Line 4}}",auditorAddressLine4);
  body.replaceText("{{Date}}",dateOfLetterIssue);

  doc.saveAndClose();

}

Currently the line var copy = templateFile.makeCopy(auditorFirmName, templateFolder); is creating a copy of the original doc with the file name of the auditor firm as I have requested. But what I would like to do is create a file name with the auditor firm name and the wording template for example. Or a fixed piece of text that is not a variable. Eg currently the file will save as John Smith Auditors where I want it to save as John Smith Auditors Template. Where John Smith stays as a variable but the word Template would always remain fixed. Is this possible?

How about changing this line var copy = templateFile.makeCopy(auditorFirmName, templateFolder); to this var copy = templateFile.makeCopy(auditorFirmName + template, templateFolder); and add a const template="whatever words you want to add"; earlier in the file near the top. You could just add + "Template" if you like but typically your needs tend to change so the use of a variable may be useful but it's up to you. If I'm not understanding you question I apologize.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM