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

2024年5月29日水曜日

Google Slidesで表の枠線を設定したい - Set table borders in Google Slides


この記事で実行するコードは、以下のリンク先でも利用したGoogle Slides APIを追加する必要があります。
The code executed in this article requires the Google Slides API, which was also used in the link below.


今回は、Google Slidesで現在選択している表の枠線を操作するコードを試しました。
This time, I tried a script to manipulate the borders of the currently selected table in Google Slides.


今回の例では、選択した表の外側の枠線を4ptにします。
In this example, the outer border of the selected table is set to 4pt.



手動でやる場合、「枠線の色」「枠線の太さ」は上部メニューの下にあるアイコンから設定できます。
When doing it manually, you can set the 'border color' and 'border weight' from the icons located below the top menu.

枠線の範囲は表の右上の▼ボタンをクリックして表示される中から選択できます。
You can select the border range from the options that appear when you click the ▼ button located at the top right of the table.



実行手順 - Procedures


コードを実行する前に、3行3列の表を配置して選択しておきます。
Before running the code, place and select a 3-row, 3-column table on the slide.


Apps Script > エディタ > サービス > Google Slides API > 追加
Apps Script > Editor > Services > Google Slides API > Add


エディタに以下のCode.gsを書いて保存し、setTableBorders()を実行します。
Write the Code.gs below in the editor, save it, and then execute the setTableBorders() function.


選択した表の枠線が4ptになります。
The border of the selected table will be set to 4pt.



Code.gs
function setTableBorders() {
var presentation = SlidesApp.getActivePresentation();
var selection = presentation.getSelection();
var pageElement = selection.getPageElementRange().getPageElements()[0];
var table = pageElement.asTable();
var presentationId = presentation.getId();
var objectId = table.getObjectId();
var resource = {
"requests": [
{
"updateTableBorderProperties": {
"objectId": objectId,
"borderPosition": "OUTER",
"tableBorderProperties": {
"tableBorderFill": {
"solidFill": {
"color": {
"rgbColor": {
"red": 0,
"green": 0,
"blue": 0,
}
// "themeColor": "DARK1"// instead of rgbColor
},
"alpha": 1
}
},
"weight": {
"magnitude": 4,
"unit": "pt"
}
},
"fields": "tableBorderFill.solidFill.color,tableBorderFill.solidFill.alpha,weight"
}
}
]
}
Slides.Presentations.batchUpdate(resource, presentationId);
}


Reference

Is it possible to update table cell borders in Google Slides using Google App Script?

UpdateTableBorderPropertiesRequest

TableBorderProperties

TableBorderFill

SolidFill

OpaqueColor

RgbColor

ThemeColorType

BorderPosition

Google Slidesの表でセルを結合したい - merge cells in a table on Google Slides


Latest post

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

IssueTracker > Apps Script issues https://issuetracker.google.com/savedsearches/566234 Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが...