[英]apps script - google slide - replaceAllText in table
`嗨!
我正在嘗試替換谷歌幻燈片所有表格中所有單元格中的文本。 我在形狀方面取得了成功,但在表格和單元格方面卻失敗了……
當我循環使用 forEach 時。 我只能到達桌子的前兩個單元格。 如果我嘗試使用 for 循環或一個一個地訪問所有對象(使用 getCell(1.0)、getCell(2.0) 等...),function 將不再起作用。
這是我當前的代碼
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);
})
})
對此的任何幫助將不勝感激!
目標是自動化我的谷歌幻燈片並替換一些變量。 用谷歌表格。
提前致謝`
我相信您在問題中的目標如下。
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..
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..
在這種情況下,如何進行以下修改?
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));
}
}
})
})
}
replaceObj
替換表格中的文本。replaceObj
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.