简体   繁体   English

如何在谷歌应用脚本中部分更改文件名?

[英]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);当前行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.例如,目前该文件将保存为 John Smith Auditors,我希望它保存为 John Smith Auditors 模板。 Where John Smith stays as a variable but the word Template would always remain fixed. John Smith 作为变量保留的位置,但 Template 一词始终保持固定。 Is this possible?这可能吗?

How about changing this line var copy = templateFile.makeCopy(auditorFirmName, templateFolder);如何更改这一行var copy = templateFile.makeCopy(auditorFirmName, templateFolder); to this var copy = templateFile.makeCopy(auditorFirmName + template, templateFolder);到这个var copy = templateFile.makeCopy(auditorFirmName + template, templateFolder); and add a const template="whatever words you want to add";并添加一个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.如果您愿意,您可以添加+ "Template" ,但通常您的需求往往会发生变化,因此使用变量可能很有用,但这取决于您。 If I'm not understanding you question I apologize.如果我不理解你的问题,我很抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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