Tables in Slides not like tables in Docs?

60 views
Skip to first unread message

Brian Rice

unread,
Jan 7, 2025, 4:19:00 AMJan 7
to Google Apps Script Community
I want to add rows to a table in a Slide presentation. The Slides API coverage of tables seems sparse compared to that in Docs; for example, there is no editAsText() method. 

I've seen code on the interwebz that seems to append a row to a table by calling the table's push() method, but when I try this I get "push is not a function". It also isn't clear to me how one does raw API calls in an Apps Script that is attached to a Google Doc.

How do people handle the task of creating or modifying tables in Slides? I'd be grateful for any tips, or even working sample code.

Ed Robinson

unread,
Jan 7, 2025, 9:05:04 PMJan 7
to Google Apps Script Community
Hi Brian,
you're right the Google Slides table methods are very different to the Google Docs table methods.

This Apps Script function shows how to programmatically add a row to a table in Google Slides:
- adds a new slide to the current presentation
- Adds a table to the slide
- Appends a row, then finally
- Puts some text into the first cell of the row

If you're familiar to programming Google Docs, Slides is similar that there are two programming interfaces: the Slides service (used in the sample below), and the Slides REST API. Both have different capabilities. You can do most things with the Slides service, the unique capability the Rest API offers is the ability to get a thumbnail image of a Slide.

Happy to help more if you have any questions.

Regards,
Ed



function myFunction() {
var mySlide = SlidesApp.getActivePresentation().appendSlide()
var myTable = mySlide.insertTable(2,2)
var myRow = myTable.appendRow()
myRow.getCell(0).getText().setText("Hello World")
}

Brian Rice

unread,
Jan 8, 2025, 12:40:26 PMJan 8
to Google Apps Script Community

Thanks, Ed! This approach does appear to work for me in a small test case; now I am working on applying it to my actual project. It seems that a part of my problem was my fingers' insatiable craving to type .getCell[1] when what I mean is .getCell(1). And .getSlides[1] when what I mean is .getSlides()[1], etc etc etc.

Ed Robinson

unread,
Jan 8, 2025, 10:35:12 PMJan 8
to Google Apps Script Community
Great. This approach will work as long as the cell text is unformatted. If you want to bold/italic some characters in the cell, programmatically doing this gets more complicated (same situation with Docs tables)
Reply all
Reply to author
Forward
0 new messages