【问题标题】:How can I delete empty columns from a table in a Google Slides presentation with Apps Script如何使用 Apps 脚本从 Google 幻灯片演示文稿中的表格中删除空列
【发布时间】:2021-07-26 18:48:18
【问题描述】:

我有一个谷歌应用程序脚本,可以将数据从谷歌表格复制到谷歌幻灯片模板的副本中。数据被复制到幻灯片模板中的占位符表格中,因此有时幻灯片上的表格中会有额外的空白行,具体取决于工作表中输入的内容。

有人知道使用谷歌应用脚​​本从谷歌幻灯片上的表格中删除多余行的方法吗?

我看到 this similar post 在 google docs 表上做同样的事情,但看起来 Presentation class 没有该答案中使用的 getTables() 方法。

谢谢!

【问题讨论】:

    标签: google-apps-script google-slides


    【解决方案1】:

    建议

    您可以尝试以下示例 Google 幻灯片 bound script,它会检查幻灯片演示表上的每一行,然后删除所有检测到的空行:

    示例脚本

    function removeEmptyRow() {
      var presentation = SlidesApp.getActivePresentation().getSlides()[0]; //Get the first slide
      var table = presentation.getTables()[0]; //Get the first table on the slide
    
      for(var col=0; col <= table.getNumColumns()-1; col++){
        for(var row=0; row<=table.getNumRows()-1; row++){
          var cellValue = table.getCell(row,col).getText().asString();
          if(cellValue.length == 1){ //check if current row is emtpy
            Logger.log("Row #"+row+" in column #"+col+" is empty");
            table.getRow(row).remove(); //remove this row index on the table
          }
        }
      }
    }
    

    参考:

    Class TableRow

    Class Slides getTables()

    样本结果

    幻灯片演示表格示例

    运行脚本后:

    从表中删除了 2 个空行

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-19
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-23
      相关资源
      最近更新 更多