[英]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.