模板文本文档
Templating text document
我正在尝试创建用于创建合同的脚本。因为这将在 'Template File which is going to be text file on gDrive' 示例中:
Client's VAT: $VAT
Client's Name: $Clients_name
我如何获取此文件内容(getBody(),它仅适用于文档类型,但您无法访问文档实例,因为我发现的所有可能性都会将我引导至文件实例..)
我的目标是获取 'Template File' 的精确副本并通过他更改以美元开头的单词,根据 HTTP 请求的值更改它们。 (这部分已经完成了。)
编辑:
你可能会对我的尝试感兴趣(或者它可以帮助别人)
function createContract(obj)
{
const templateName = "RC - Contract Template";
const templateFile = getTemplate(templateName);
const templateText = templateFile.getAs("plain/text");
const file = DocumentApp.create(obj.filename);
const body = file.getBody();
const url = file.getUrl();
body.insertParagraph(0, templateText);
HtmlService.createHtmlOutput(url);
}
注意: getTemplate() 是遍历所有文件并返回名称为 'RC - Contract Template'
的文件实例的函数
经过一番搜索,我发现 google 与 "File"、"Document" 等有很大区别
如果有人遇到同样的情况,这是我获取文件内容的方法,当你只知道名字时:
function getTemplateId(filename) {
const files = DriveApp.getFilesByType(MimeType.GOOGLE_DOCS);
while (files.hasNext()) {
var file = files.next();
if (file.getName() == filename) return file.getId();
}
return HtmlService.createHtmlOutput("Required template: " + filename + " does not exists!");
}
注意:移动了 OP 从问题发布的解决方案:
我正在尝试创建用于创建合同的脚本。因为这将在 'Template File which is going to be text file on gDrive' 示例中:
Client's VAT: $VAT
Client's Name: $Clients_name
我如何获取此文件内容(getBody(),它仅适用于文档类型,但您无法访问文档实例,因为我发现的所有可能性都会将我引导至文件实例..)
我的目标是获取 'Template File' 的精确副本并通过他更改以美元开头的单词,根据 HTTP 请求的值更改它们。 (这部分已经完成了。)
编辑:
你可能会对我的尝试感兴趣(或者它可以帮助别人)
function createContract(obj)
{
const templateName = "RC - Contract Template";
const templateFile = getTemplate(templateName);
const templateText = templateFile.getAs("plain/text");
const file = DocumentApp.create(obj.filename);
const body = file.getBody();
const url = file.getUrl();
body.insertParagraph(0, templateText);
HtmlService.createHtmlOutput(url);
}
注意: getTemplate() 是遍历所有文件并返回名称为 'RC - Contract Template'
的文件实例的函数经过一番搜索,我发现 google 与 "File"、"Document" 等有很大区别
如果有人遇到同样的情况,这是我获取文件内容的方法,当你只知道名字时:
function getTemplateId(filename) {
const files = DriveApp.getFilesByType(MimeType.GOOGLE_DOCS);
while (files.hasNext()) {
var file = files.next();
if (file.getName() == filename) return file.getId();
}
return HtmlService.createHtmlOutput("Required template: " + filename + " does not exists!");
}
注意:移动了 OP 从问题发布的解决方案: