【发布时间】:2022-01-31 05:30:28
【问题描述】:
我目前有两张谷歌表格。
- 1 是一个主表,其中每一行都包含特定于个别学生的信息。
- 另一个是我希望复制的模板,然后用主表特定行中的信息填充(这样每个学生都会有自己的 googlsheet,其中只有他们的信息。
我遇到的问题是我不知道如何一次导入整行。
我最初的尝试是基于this idea。但是,由于我试图导入大约 1000 个不同的单元格(是的,都在同一行中),因此脚本在为 60 名学生完成脚本之前超时。我认为导入整行而不是使用“createTextFinder”替换所有 1000 个引用会更快。我还读到使用触发器可能是脚本超时的一种解决方法 - 但我也无法弄清楚(还)。我很乐意使用这两种解决方案。 我认为您需要参考的代码部分如下。还有我的主表的this is a copy。 [更新] This 是模板表的副本(请注意,我制作了副本,因此表 ID 与代码不匹配)。
// Loop over the rows
data.forEach((row,i) => {
// Identify whether notification has been sent
if (row[936] === 'send') {
//Enter collected info into Requirements Template
const googleSheetTemplate = DriveApp.getFileById('1DZZVZ5y1r5RmP4dMYmZuBQWPzIPp6eVZsdUrrador3o');
const destinationFolder = DriveApp.getFolderById('10px5WeNyVa9jSNQjCKV9jwcacCDvpByp');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data');
const copy = googleSheetTemplate.makeCopy(`${row[1]}, ${row[2]}, ${row[938]} Report Card` , destinationFolder);
const newSheet = SpreadsheetApp.openById(copy.getId());
const A1 = newSheet.getDataRange();
for (currentsheet = 0; currentsheet < newSheet.getSheets().length; currentsheet++) {
const a1 = newSheet.getSheets()[currentsheet].getDataRange();
A1.createTextFinder("{{StudentEmail}}").replaceAllWith(row[0]);
A1.createTextFinder("{{FirstName}}").replaceAllWith(row[1]);
A1.createTextFinder("{{LastName}}").replaceAllWith(row[2]);
【问题讨论】:
-
关于
The issue I'm having is that I can't figure out how to import an entire row all at once.,能否提供googleSheetTemplate的示例电子表格作为图片?而且,在您的情况下,您的脚本工作正常。但是您想降低脚本的处理成本。我的理解正确吗? -
感谢您的帮助!我在上面的模板副本中添加了一个链接(因为它全部输入一行,图像只会捕获前几列)。你是对的,我正在尝试降低流程成本,尽管我也可以使用谷歌脚本超时的解决方法。
-
感谢您的回复。根据您的回复,我提出了一个修改后的脚本作为答案。你能确认一下吗?如果我误解了您的目标并且没有用,我深表歉意。
标签: google-apps-script google-sheets replace