复制主 Google 幻灯片演示 + 从表格中填充数据

huangapple go评论71阅读模式
英文:

Duplicate master Google Slides deck + Populate it from Sheets

问题

我有两个分别运行良好的脚本,但我需要将它们合并。

我试图实现的是,从Google表格中,某人将运行一个脚本,并且:

  1. 将制作主Google幻灯片演示文稿的副本,并根据名为'Generate'的表格更新名称
  2. 使用占位符,从名为'Data'的表格中更新此副本

对于第1点,我有以下代码:

function createFolderAndFiles() {
  const templateGetStarted = '<模板演示文稿的ID>';

  let sheet = SpreadsheetApp.getActive().getSheetByName('Generate');
  let data = sheet.getDataRange().getValues();

  let wbrDate = data[1][0];
  let getStarted = data[1][1];

  DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`)
}

对于第2点,我有以下代码:

function fillTemplate() {

 var PRESENTATION_ID = "<在第1点中创建的模板演示文稿副本的ID>";

 var presentation = SlidesApp.openById(PRESENTATION_ID);

 var values = SpreadsheetApp.getActive().getSheetByName('Data').getDataRange().getValues();

 values.forEach(function(row) {
   var templateVariable = row[0]; // 第一列包含变量名称
   var templateValue = row[1]; // 第二列包含值
   presentation.replaceAllText(templateVariable, templateValue);
 });

}

所以,正如我提到的,它们分别运行得很好。我只需要找到一种将它们合并成一个函数的方法,可以运行并自动制作模板演示文稿的副本,并从电子表格中自动填充数据。

非常感谢任何帮助!

英文:

I have two scripts that work well separately but I need to combine them.

What I am trying to achieve is that from a Google Sheets, someone will run a script and:

  1. A copy of a master Google Slides deck will be made and the name will be updated based on a sheet called 'Generate'
  2. This copy will be updated with values from the sheet called 'Data', using placeholders

For point 1 I have this code:

function createFolderAndFiles() {
  const templateGetStarted = &#39;&lt;ID OF MY TEMPLATE DECK&gt;&#39;;

let sheet = SpreadsheetApp.getActive().getSheetByName(&#39;Generate&#39;);
let data = sheet.getDataRange().getValues();

let wbrDate = data[1][0];
let getStarted = data[1][1];


  DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`)
}

And for point 2 I have this code:

function fillTemplate() {

 var PRESENTATION_ID = &quot;&lt;THE ID OF THE JUST CREATED COPY OF THE TEMPLATE DECK IN POINT 1&gt;&quot;;

 var presentation = SlidesApp.openById(PRESENTATION_ID);

 var values = SpreadsheetApp.getActive().getSheetByName(&#39;Data&#39;).getDataRange().getValues();

 values.forEach(function(row) {
   var templateVariable = row[0]; // First column contains variable names
   var templateValue = row[1]; // Second column contains values
   presentation.replaceAllText(templateVariable, templateValue);
 });

}

So as I mentioned, they work great separetely. I just need to find a way to combine them both into 1 function that you can run and a copy of the template deck will be made and it will be filled automatically with data from the spreadsheet.

Any help is much appreciated!

答案1

得分: 1

你可以尝试满足第一个函数的最后一行和第二个函数的第一行。

var PRESENTATION_ID = DriveApp.getFileById(templateGetStarted).makeCopy(WBR - ${wbrDate}).getId()

英文:

You can try meeting your last line of the first function and first line of the second one

var PRESENTATION_ID = DriveApp.getFileById(templateGetStarted).makeCopy(`WBR - ${wbrDate}`).getId()

huangapple
  • 本文由 发表于 2023年2月27日 03:01:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定