Search code examples
google-apps-scriptgoogle-slides-apigoogle-slides

Are there certain Google Slides AppScript that are documented but not supported?


I am trying to manipulate a table in Google Slides, but there seem to be documented operations that throw errors in AppScript.

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

The commented out lines throw the following errors:

Updating the size of this page element type is not supported.

var table = (slides[page])
.insertTable(rows, columns)
.setTop (0)
.setLeft(0)
//.setWidth(presentation.getPageWidth());
//.setHeight(presentation.getPageHeight());

Solution

  • How about this answer? I have also confirmed the same situation with you. I think that this might be a bug. Because when Slides API is used, the table which adjusted the width and height can be created. So in the current workaround, when the size of the table is required to be adjusted when the table is created, I create the table using Slides API. The sample script is as follows.

    In order to use the sample script, before you run the script, please enable Slides API at Advanced Google Services and API console as follows.

    Enable Slides API v1 at Advanced Google Services

    • On script editor
      • Resources -> Advanced Google Services
      • Turn on Google Slides API v1

    Enable Slides API at API console

    • On script editor
      • Resources -> Cloud Platform project
      • View API console
      • At Getting started, click "Explore and enable APIs".
      • At left side, click Library.
      • At "Search for APIs & services", input "Slides". And click "Google Slides API".
      • Click Enable button.
      • If API has already been enabled, please don't turn off.

    Sample script 1:

    When your script is modified using Slides API, it becomes as follows.

    var presentation = SlidesApp.getActivePresentation();
    var slides = presentation.getSlides();
    var resource = {"requests":[{"createTable": {
      "rows": 2,
      "columns": 3,
      "elementProperties": {
        "size": {
          "width": {"unit": "PT", "magnitude": presentation.getPageWidth()},
          "height": {"unit": "PT", "magnitude": presentation.getPageHeight()},
        },
        "pageObjectId": slides[0].getObjectId()},
      }
    }]};
    Slides.Presentations.batchUpdate(resource, presentation.getId());
    

    Sample script 2:

    If you want to modify the size of the existing table, you can use the following script.

    var presentation = SlidesApp.getActivePresentation();
    var slides = presentation.getSlides();
    var table = slides[0].getTables()[0];
    var tableObjectId = table.getObjectId();
    var resource = {"requests": [
      {"updateTableColumnProperties": {
        "objectId": tableObjectId,
        "tableColumnProperties": {"columnWidth": {"unit": "PT", "magnitude": presentation.getPageWidth() / table.getNumColumns()}}, "fields": "*"}
      },
      {"updateTableRowProperties": {
        "objectId": tableObjectId,
        "tableRowProperties": {"minRowHeight":{"unit": "PT", "magnitude": presentation.getPageHeight() / table.getNumRows()}},"fields":"*"}
      }
    ]};
    Slides.Presentations.batchUpdate(resource, presentation.getId());
    

    References :

    If this was not the workaround you want, I apologize.