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

2024年6月11日火曜日

スライドの表でセルのフォントを変えたい - change the cell font in a table in Slides using Apps Script


Google Slidesに配置した表内のフォントを変更したくて試したコードです。
I tried to change the font style of text in a table in Google Slides using the following Apps Script.


選択した表内のフォントをImpactへ変更します。
Change the font of the selected table to Impact.



Apps Script


Code.gs
function setTableCellFont() {
const presentation = SlidesApp.getActivePresentation();
const selection = presentation.getSelection();
const pageElement = selection.getPageElementRange().getPageElements()[0];
const table = pageElement.asTable();
const numRows = table.getNumRows();
const numColumns = table.getNumColumns();
for (let row = 0; row < numRows; row++) {
for (let col = 0; col < numColumns; col++) {
const cell = table.getCell(row, col);
const textRange = cell.getText();
const textStyle = textRange.getTextStyle();
textStyle.setFontFamily('Impact');
}
}
}


Reference

Class TextStyle > setFontFamily(fontFamily)

Latest post

Google Formsで記述式の質問に字数制限を設定したい

記述式の質問には「回答の検証」を設定することができます フォームの編集画面 右下の︙メニューで「回答の検証」を選択します 検証方法には「数値」「テキスト」「長さ」「正規表現」という種類があります 今回は字数制限したいので「長さ」を選びます 長さには「最大文字数」か「最小文字数」を...