在不丢失原始模板的情况下使用 google 张数据创建新的幻灯片副本

Creating new copies of slides with data from google sheets without loosing original template

我制作了一个脚本,用 google sheet 中的信息替换 google 幻灯片中的占位符文本。 但是,一旦我有了 运行 脚本,一旦我的幻灯片模板被注入的信息覆盖。

如何在生成幻灯片的新副本时保留原始模板?

我使用“SpreadsheetApp.openById”获取传播sheet,我还可以使用“DriveApp.getFileById”和“makeCopy( )”。但是我的原始模板仍然被覆盖,我所有的占位符标签 {{tag}} 都丢失了。

我使用此函数替换 google 幻灯片中的元素:

values.forEach(function(row){
var templatevariable= row[0];
var templatevalue= row[1]
Presentation.replaceAllText(templatevariable,templatevalue);  
})

创建副本,然后处理副本。


var copiedFile = createCopyUsingDriveApp()

values.forEach(function(row){
  var templatevariable= row[0];
  var templatevalue= row[1]
  copiedField.replaceAllText(templatevariable,templatevalue);  
})


function createCopyUsingDriveApp() {
 // The Id of the presentation to copy
 var templateId = "<SLIDES_ID>";

 // Create a copy of the presentation using DriveApp
 var template = DriveApp.getFileById(templateId);
 var fileName = template.getName();
 var copy = template.makeCopy();
 return copy.setName("Copy of " + fileName);
}