簡體   English   中英

應用程序腳本 - 谷歌幻燈片 - 表格中的 replaceAllText

[英]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..
  • 您想要使用 Google Apps 腳本替換 Google 幻燈片中所有幻燈片的表格中的文本。

在這種情況下,如何進行以下修改?

修改腳本:

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));
        }
      }
    })
  })
}
  • 通過此修改,使用 Google Slides 中所有幻燈片的所有表格,並使用replaceObj替換表格中的文本。
  • 在本次修改中,您可以將多個替換模式設置為replaceObj

參考:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM