`Hi !
I'm trying to replace text in all cells in all table of a google slide. I successed with shapes, but not with tables and cells..
And when i loop in using forEach. I only can reach the two first cells of my table. If i try to reach all with a for loop or one by one (with getCell(1.0), getCell(2.0) etc...), the function doesn't work anymore.
Here my current code
var slides = deck.getSlides();
slides.forEach(function(slide){
var tables = (slide.getTables());
tables.forEach(function(table){
table.getCell(0,0).getText().replaceAllText('{{entreprise}}',entreprise);
table.getCell(1,0).getText().replaceAllText('{{entreprise}}',entreprise);
})
})
Any help with this will be very much appreciated!
the goal is to automated my google slides and replace some variables. with a google form.
Thanks by advance`
CodePudding user response:
I believe your goal in your question is as follows.
- You want to resolve your current issue of
I'm trying to replace text in all cells in all table of a google slide. I successed with shapes, but not with tables and cells..
. - You want to replace texts in tables of all slides in the Google Slides using Google Apps Script.
In this case, how about the following modification?
Modified script:
function myFunction() {
// Please set your value. You can set multiple patterns.
var replaceObj = [
{ "from": "{{entreprise}}", "to": "sample1" },
,
,
];
var deck = SlidesApp.getActivePresentation();
var slides = deck.getSlides();
slides.forEach(function (slide) {
var tables = slide.getTables();
tables.forEach(function (table) {
for (var r = 0; r < table.getNumRows(); r ) {
for (var c = 0; c < table.getRow(r).getNumCells(); c ) {
replaceObj.forEach(({ from, to }) => table.getCell(r, c).getText().replaceAllText(from, to));
}
}
})
})
}
- By this modification, all tables of all slides in Google Slides are used, and the texts in tables are replaced using
replaceObj
. - In this modification, you can set multiple replace patterns to
replaceObj
.