简体   繁体   中英

Using Google appscript to refresh tables pasted in from Google sheets into Google slides

This question here has as succinct solution for updating Google Sheets charts linked to Google slides .

function onOpen() {
  var ui = SlidesApp.getUi();
  ui.createMenu('Custom Menu')
  .addItem('Batch Update Charts', 'batchUpdate')
  .addToUi();
}

function batchUpdate(){

  var gotSlides = SlidesApp.getActivePresentation().getSlides();

  for (var i = 0; i < gotSlides.length; i++) {
    var slide = gotSlides[i];
    var sheetsCharts = slide.getSheetsCharts();
    for (var k = 0; k < sheetsCharts.length; k++) {
      var shChart = sheetsCharts[k];
      shChart.refresh();
    }
  }
}

I wish to do the same thing but with a table pasted into Google Slides from Google Sheets. I can't see how this would look in the AppScript API for Google Slides . Can someone point out a way forward?

Latest update: There is now an option in Slides's Tools drop-down menu to see all Linked Objects; the menu that appears has the option at the bottom to "Update all".

在此处输入图片说明 在此处输入图片说明

I found this workaround in the issuetracker link provided by Leo as a comment to OP on Oct 30 '18:

"If anyone is reading this who wants the feature, one solution is to create a "table chart" in your sheet, from your existing table (that you were trying to link/update). It doesn't allow you to copy and paste from Sheets to Slides, but within Slides if you go to Insert -> Chart -> From Spreadsheet, then choose your sheet and chart (table). You can then use app scripts to automatically update it, as you can with a chart."

From ad...@lovecrafts.com

As pointed, it is not possible to do it using Google App Script, but I found a workaround using Python and Selenium, with can be ran online with Google Colab.

Is is possible to use Selenium to click on a button in a Google Slides Presentation?

I could not find the refresh function for table object the same way it has for sheetsChart. The script does identify PageElement as Table so it has to be in table reference.

https://developers.google.com/apps-script/reference/slides/table

https://developers.google.com/apps-script/reference/slides/sheets-chart#refresh()

First you can use a similar variable as

var sheetsTables = slide.getTables() 

and then use a for() loop to update each table in each slide. However, I don´t know which method you can use. If you know of one, please share.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM