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


Google Slidesの表内の指定文字を置換して太字にしたい - Replace and bold specific text within a table in Google Slides

In this example, I combined the code from the following link.

Google Slidesで現在選択している表内の特定のセル内にある指定した文字を置換して太字にしてみます。
I will try to replace and bold specific text within a specific cell of the currently selected table in Google Slides.


Prepare a table with 3 rows and 2 columns, and enter text in the second row and second column.

その際、太字にしたい単語を [ ] で囲んでおきます。
Enclose the word you want to bold in square brackets [].

The text used in this example.

Trying to replace and bold a specific text within a table in Google Slides using Google Apps Script.

今回の例では、replace と bold を [] で囲んでいます。
In this example, "replace" and "bold" are enclosed in square brackets [].

表を選択して replaceBoldTargetWords() を実行すると、replace と bold の [] が空文字に置き換わり、太字になります。
After selecting the table and executing replaceBoldTargetWords(), the square brackets [] are removed, and the text "replace" and "bold" are made bold.

Apps Script
function replaceBoldTargetWords() {
const table = getSelectedTable();
const row = 1;
const col = 1;
const cell = table.getCell(row, col);

const textRange = cell.getText();
let text = textRange.asString();
let values = text.match(/(?<=\[).+?(?=\])/g);

text = text.replace(/\[|\]/g, '');
for (let i = 0; i < values.length; i++) {
const value = values[i];
const startIndex = text.indexOf(value);
const endIndex = startIndex + value.length;
textRange.getRange(startIndex, endIndex).getTextStyle().setBold(true);

function getSelectedTable() {
const presentation = SlidesApp.getActivePresentation();
const selection = presentation.getSelection();
const pageElement = selection.getPageElementRange().getPageElements()[0];
const table = pageElement.asTable();
return table;


最初は単語を太字にしてから [ ] を空文字にしようとしましたが、それだと [] が消えるだけで単語が太字になりませんでした。
At first, I tried to make the words bold and then replace the square brackets [] with empty strings, but that only removed the brackets and did not bold the words.

Since the above code overwrites the entire text when replacing, I tried the following steps, which led to the code I wrote this time.

1. [ ] を目印にして太字にしたい単語を取得する
Retrieve the words to be bolded using the square brackets [] as markers.

let values = text.match(/(?<=\[).+?(?=\])/g);

2. 全テキストを取得して[ ] を空文字に置換する
Replace all square brackets [] with empty strings after retrieving the entire text.

text = text.replace(/\[|\]/g, '');

3. 取得しておいた単語を太字にする
Bold the retrieved words

textRange.getRange(startIndex, endIndex).getTextStyle().setBold(true);

Please note that with the above code, if the same word appears before the retrieved word, the previous word will be bolded.

Since this behavior is outside the scope of what I wanted to achieve this time, I am allowing it in this article.


Google Slidesの表内の指定文字を太字にしたい - Bold specific text within a table in Google Slides

Google Slidesの表のテキストを置換したい - Replace text in a table in Google Slides

Latest post

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

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