英文:
Duplicate master Google Slides deck + Populate it from Sheets
问题
我有两个分别运行良好的脚本,但我需要将它们合并。
我试图实现的是,从Google表格中,某人将运行一个脚本,并且:
- 将制作主Google幻灯片演示文稿的副本,并根据名为'Generate'的表格更新名称
- 使用占位符,从名为'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:
- A copy of a master Google Slides deck will be made and the name will be updated based on a sheet called 'Generate'
- 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 = '<ID OF MY TEMPLATE DECK>';
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}`)
}
And for point 2 I have this code:
function fillTemplate() {
var PRESENTATION_ID = "<THE ID OF THE JUST CREATED COPY OF THE TEMPLATE DECK IN POINT 1>";
var presentation = SlidesApp.openById(PRESENTATION_ID);
var values = SpreadsheetApp.getActive().getSheetByName('Data').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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论