[英]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();
}
当前行var copy = templateFile.makeCopy(auditorFirmName, templateFolder);
正在按照我的要求使用审计公司的文件名创建原始文档的副本。 但我想做的是创建一个包含审计公司名称和措辞模板的文件名。 或者不是变量的固定文本。 例如,目前该文件将保存为 John Smith Auditors,我希望它保存为 John Smith Auditors 模板。 John Smith 作为变量保留的位置,但 Template 一词始终保持固定。 这可能吗?
如何更改这一行var copy = templateFile.makeCopy(auditorFirmName, templateFolder);
到这个var copy = templateFile.makeCopy(auditorFirmName + template, templateFolder);
并添加一个const template="whatever words you want to add";
在靠近顶部的文件中。 如果您愿意,您可以添加+ "Template"
,但通常您的需求往往会发生变化,因此使用变量可能很有用,但这取决于您。 如果我不理解你的问题,我很抱歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.