I'm using Google Apps Script to manipulate a Slides file. I want to create a table on a slide and set the height/width of a row/column, of a particular cell, or of the table overall. The documentation is mysteriously silent on this, except for this page which doesn't seem very promising.
Anybody know a workaround for this, or do I have to resort to the Slides API?
I could understand like above.
You can set the height and width of a table using Slides Service, when new table is created. But in the current stage, the height and width of created table and the the specific cell cannot be modified using using Slides Service, yet. I think that this might be achieved in the future update.
As a current workaround, when Slides API is used, this can be achieved.
In this sample script, Slides Service is used. New table is created with 300 point and 100 point in the width and height on the 1st page of Slides, respectively.
var slides = SlidesApp.getActivePresentation();
var slide = slides.getSlides()[0];
var table = slide.insertTable(3, 3, 0, 0, 300, 100);
In this sample script, Slides API is used. The the width and height of the cell "B2" of table on the 1st page are modified to 300 point and 100 point, respectively.
var slides = SlidesApp.getActivePresentation();
var slide = slides.getSlides()[0];
var objectId = slide.getTables()[0].getObjectId();
SlidesApp.getActivePresentation().saveAndClose();
var resource = {requests: [
{updateTableColumnProperties: {tableColumnProperties:
{columnWidth: {magnitude: 300, unit: "PT"}},
columnIndices: [1],
objectId: objectId,
fields: "columnWidth"
}},
{updateTableRowProperties: {tableRowProperties:
{minRowHeight: {magnitude: 100, unit: "PT"}},
rowIndices: [1],
objectId: objectId,
fields: "minRowHeight"
}}
]};
Slides.Presentations.batchUpdate(resource, slides.getId());
In this sample script, using only Slides API, the result of "Sample script 1" and "Sample script 2" can be obtained.
var slides = SlidesApp.getActivePresentation();
var slide = slides.getSlides()[0];
var objectId = "sampleTable" + (new Date().getTime());
var resource = {requests: [
{createTable: {
rows: 3,
columns: 3,
elementProperties: {pageObjectId: slide.getObjectId(), size: {width: {magnitude: 300, unit: "PT"}, height: {magnitude: 100, unit: "PT"}}},
objectId: objectId
}},
{updateTableColumnProperties: {
tableColumnProperties: {columnWidth: {magnitude: 300, unit: "PT"}},
columnIndices: [1],
objectId: objectId,
fields: "columnWidth"
}},
{updateTableRowProperties: {
tableRowProperties: {minRowHeight: {magnitude: 100, unit: "PT"}},
rowIndices: [1],
objectId: objectId,
fields: "minRowHeight"
}}
]};
Slides.Presentations.batchUpdate(resource, slides.getId());