Apps Script公式リファレンス: Apps Script Reference |障害・課題追跡: IssueTracker |Google Workspace: Status Dashboard - Summary


Google Slidesで現在選択している表に値を入れたい5 - Insert values into the active table5

I also wrote articles on how to insert values into a table in Google Slides using Apps Script. You can find them at the following links.

This time, I combined the approaches from the above.

Before running the code, place and select a 4-row, 4-column table on the slide.

Set the first row as the header.
function setValuesToSlideTable() {
var text = `get: 得る: v.: To obtain or receive something.
take: 取る: v.: To carry or move something from one place to another.
make: 作る: v.: To create or produce something.
give: 与える: v.: To offer or hand over something to someone.`;
var values = text.split("\n");
var arrays = []
for(var i = 0; i < values.length; i++) {
var row = values[i];
var cols = row.split(": ");
var array = [cols[0], cols[1], cols[2], cols[3]];

function insertValuesIntoSelectedTable(values) {
var presentation = SlidesApp.getActivePresentation();
var selection = presentation.getSelection();
var pageElement = selection.getPageElementRange().getPageElements()[0];
var table = pageElement.asTable();
var tableRows = table.getNumRows()-1;// Subtract 1 since the first row of the table is a header.

if(values.length !== tableRows) {
var diffRows = values.length - tableRows;
if(0 < diffRows) {
addRows(table, diffRows);
} else {
deleteRows(table, Math.abs(diffRows));
setValuesInTable(table, values, 1, 0);// Inserting point is the second row(index 1) and first column (index 0)

function setValuesInTable(table, values, startRow = 0, startCol = 0) {
for (var row = 0; row < values.length; row++) {
for (var col = 0; col < values[row].length; col++) {
if (row + startRow < table.getNumRows() && col + startCol < table.getNumColumns()) {
table.getCell(row + startRow, col + startCol).getText().setText(values[row][col]);

function addRows(table, diffRows) {
for(var i = 0; i < diffRows; i++) {

function deleteRows(table, diffRows) {
for(var i = 0; i < diffRows; i++) {
table.getRow(table.getNumRows() - 1).remove();

setValuesToSlideTable() を実行すると、Code.gs内に書いたtextの値が表に入力されます。
After executing "setValuesToSlideTable()" function, the values of the text variable written in will be inserted into the table.

一行足りない分は addRows(table, diffRows) で追加されます。
The missing rows in the table will be added using the "addRows(table, diffRows)" function.


Google Slidesで現在選択している表に値を入れたい - Insert values into the active table

Google Slidesの表にSpreadsheetから値を入れたい - Insert Spreadsheet values into a Slides table

Google Slidesで現在選択している表に値を入れたい4 - Insert values into the active table4

Latest post

Google Apps Scriptの障害時はIssueTrackerを見てみる - Incidents for Apps Script are reported on Issue Tracker

IssueTracker > Apps Script issues Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...