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

2024年5月13日月曜日

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


Google Slidesで、選択している表に値を入れるというのをGoogle Apps Scriptで試しました。
I tried using Google Apps Script to input values into a selected table in Google Slides.



今回使うスライドの例
An example of the slide used for this demonstration.



Code.gs
function insertValuesIntoSelectedTable() {
var presentation = SlidesApp.getActivePresentation();
var selection = presentation.getSelection();
var pageElement = selection.getPageElementRange().getPageElements()[0];
var table = pageElement.asTable();
var values = [
['Value 1', 'Value 2', 'Value 3'],
['Value 4', 'Value 5', 'Value 6'],
['Value 7', 'Value 8', 'Value 9']
];
for (var row = 0; row < values.length; row++) {
for (var col = 0; col < values[row].length; col++) {
if (row < table.getNumRows() && col < table.getNumColumns()) {
table.getCell(row, col).getText().setText(values[row][col]);
}
}
}
}


insertValuesIntoSelectedTable() を実行すると、選択した表の中に、Code.gs内で指定した値(Value 1〜9)が入力されます。
Running insertValuesIntoSelectedTable() will fill the selected table with the values specified in the Code.gs (Value 1 through 9).


Tips

上記のCode.gsは、ChatGPT4 に質問した回答をコンパクトにしたものです。
The Code.gs above is a compact version of the answer I got from ChatGPT4.


ChatGPT4が書いてくれたスクリプトの例
A script example written by ChatGPT4.


Reference


Google Slidesの表をApps Scriptで取得したい - Get tables in Slides

Latest post

Googleドライブ内の音声ファイルをiframe内で再生したい

iframe の src にGoogleドライブ内の音声ファイルを埋め込む例です (今回試した音声ファイルはmp3) Code.gs function doGet () { return HtmlService . createTemplateFromFile ( ...