如何使用 Apps 脚本生成带有嵌入式 AppScript 的 Google 文档?
我有兴趣使用我的库中的特定 Apps 脚本生成 Google 文档。 我创建文档的方式基本上是通过 Jeff Everhart 的代码看到的 此处。
是否有可能更改代码,让新的 Google 文档从一开始就嵌入嵌入式 Apps 脚本?
我的简化代码:
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('The template ID goes here');
const destinationFolder = DriveApp.getFolderById('The destination folder ID goes here');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index) {
if (index === 0 ) return;
if(row[rows[0].length - 1]) return;
const copy = googleDocTemplate.makeCopy(`First Column Name (${row[0]})`, destinationFolder);
const doc = DocumentApp.openById(copy.getId());
// Hopefully here we can have the addition of the the Apps Script on the new Docs
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index+1, rows[0].length).setValue(url);
})
}
I'm interested in generating a Google Document with a particular Apps Script from my library.
The way I have been creating the Documents has been through basically, Jeff Everhart's code as seen here.
Is it possible that the code be changed as to have the new Google Docs have an embedded Apps Script right from the get go?
My reduced code:
function createNewGoogleDocs() {
const googleDocTemplate = DriveApp.getFileById('The template ID goes here');
const destinationFolder = DriveApp.getFolderById('The destination folder ID goes here');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
const rows = sheet.getDataRange().getValues();
rows.forEach(function(row, index) {
if (index === 0 ) return;
if(row[rows[0].length - 1]) return;
const copy = googleDocTemplate.makeCopy(`First Column Name (${row[0]})`, destinationFolder);
const doc = DocumentApp.openById(copy.getId());
// Hopefully here we can have the addition of the the Apps Script on the new Docs
doc.saveAndClose();
const url = doc.getUrl();
sheet.getRange(index+1, rows[0].length).setValue(url);
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的目标是创建绑定到文档的 Apps 脚本项目,则必须从该特定文档创建它。正如文档中所述:
如果您的最终目标是创建一个包含来自不同 Apps 脚本项目的嵌入式 Apps 脚本的文档,则必须首先创建该文档/脚本作为模板,然后使用
makeCopy
创建文档/脚本的副本。我记录这个答案是为了帮助这个社区的其他人,如果您需要进一步的帮助,请随时发表评论。
If your goal is to create an Apps Script project bound to a Doc, you have to create it from that particular document. As it is said on the docs:
If your end goal is to create a Doc with an embedded Apps Script from a different Apps Script project, you would have to first create that Doc/script as a template and then use
makeCopy
to create a copy of the Doc/script.I am documenting this answer to help other people on this community, please feel free to leave a comment in your need further assistance.