Retrieving Size of Tables in Google Slides using Google Apps Script

Gists

This sample script is for retrieving the size (width and height) of a table in Google Slides using Google Apps Script.

There are no methods for directly retrieving the table size using SlidesApp yet. So I thought of a workaround using Slides API.

The modified script reflected this is as follows.

In order to use this script, please enable Slides API at Advanced Google Services and API console.

var s = SlidesApp.getActivePresentation();
var presentationId = s.getId();
var pageObjectId = s.getSlides()[0].getObjectId(); // In this sample, I use 1st page. But if you want to use other page, please get the "getObjectId".

var pageElements = Slides.Presentations.Pages.get(presentationId, pageObjectId).pageElements;
var result = [];
for (var i in pageElements) {
  var rowHeight = 0;
  var rowWidth = 0;
  if (pageElements[i].table) {
    for (var j in pageElements[i].table.tableRows) {
      rowHeight += pageElements[i].table.tableRows[j].rowHeight.magnitude / 12700;
    }
    for (var k in pageElements[i].table.tableColumns) {
      rowWidth += pageElements[i].table.tableColumns[k].columnWidth.magnitude / 12700;
    }
    result.push({Height: rowHeight, Width: rowWidth});
  }
}
Logger.log(result)

Result :

[
    {
        "Height": 200,
        "Width": 300
    }
]

Note :

Reference :

 Share!