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

2024年6月12日水曜日

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




Google Apps Scriptの障害時は IssueTracker に課題が上がっていることが多いです。
When Google Apps Script is experiencing issues, there's often an issue raised on the IssueTracker.




昨晩2024/06/11、スクリプトエディタが開けなくて見に行ったら課題が上がっていました。
Last night, on June 11th, 2024, I couldn't open the script editor, and when I checked, I found an issue had been raised.


Google Workspace Status Dashboard

Google Issue Tracker

Issue tracking system and product feature requests

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)

2024年6月10日月曜日

Google SlidesのダイアログにSpreadsheetの値を読み込みたい(datalist) - load the values from the Spreadsheet into a dialog in Google Slides.


Google Slidesのダイアログに配置したdatalistに、Spreadsheetの値を入れる機能を作ったときの備忘録です。
This is a memo for when I created a function to load values from a Spreadsheet into the options of a datalist placed in a dialog in Google Slides.




Procedures

SpreadsheetのA1〜A3にそれぞれ以下の値を入れておきます。
Enter the following values into cells A1 to A3 of the spreadsheet.
A1: option 1
A2: option 2
A3: option 3


Google SlidesのApps Scriptに以下のCode.gsを書きます。
Write the following code in Code.gs in Google Slides Apps Script.


SPREADSHEET_IDは読み込ませたい値が入ったシートのIDに置き換えます。
Replace SPREADSHEET_ID with the ID of the sheet containing the values you want to load.


modalessTemplate() を実行すると、ダイアログに配置したデータリストにシートの値が読み込まれます。
Execute the modalessTemplate() to load those data into a data list placed in a dialog in Google Slides.


リストにない option 4 を入力してsubmitをクリックします。
Enter option 4, which is not in the list, and click submit.



シートに option 4 が追加されます。
Option 4 will be added to the sheet.


ダイアログリストにも option 4 が追加されます。
The option 4 will also be added to the list in the dialog.



Apps Script


Code.gs
const ssUrl = "https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/edit#gid=0";

function modalessTemplate() {
const htmlOutput = HtmlService
.createTemplateFromFile("index")
.evaluate()
.setWidth(360)
.setHeight(240);
SlidesApp.getUi().showModelessDialog(htmlOutput, "MyGUI");
}

function returnList() {
const sheet = SpreadsheetApp.openByUrl(ssUrl).getSheets()[0];
const values = sheet.getDataRange().getValues();
const list = values.flat();
return list;
}

function setNewValue(newValue) {
const sheet = SpreadsheetApp.openByUrl(ssUrl).getSheets()[0];
const lastRow = sheet.getLastRow();
const data = sheet.getRange("A1:A" + lastRow).getValues();
for (let i = 0; i < data.length; i++) {
if (data[i][0] == newValue) {
return "failure: value already exists";
}
}
sheet.getRange("A" + (lastRow + 1)).setValue(newValue);
return "success";
}


index.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<input type="text" id="tb" list="sheetValues">
<button id="submit">submit</button>
<datalist id="sheetValues"></datalist>

<script>
function elem(id) {
return document.getElementById(id);
}

function onFailure(e) {
alert([e.message, e.stack]);
}

elem("submit").addEventListener("click", submitClicked);

getList();
function getList() {
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(createDatalist)
.returnList();
}

function createDatalist(list) {
const datalist = elem("sheetValues");
console.log(list)
for(let i = 0; i < list.length; i++) {
const option = document.createElement("option");
option.textContent = list[i];
datalist.appendChild(option);
}
}

function submitClicked() {
const newValue = elem("tb").value;
google.script.run
.withFailureHandler(onFailure)
.withSuccessHandler(successSetNewValue)
.withUserObject(newValue)
.setNewValue(newValue);
}

function successSetNewValue(message, newValue) {
console.log(message);
if(message === "success") {
const datalist = elem("sheetValues");
const option = document.createElement("option");
option.textContent = newValue;
datalist.appendChild(option);
}
}
</script>
</body>
</html>


Reference

シートのデータをdatalistに読み込みたい

スプレッドシートのurlとnameをHTMLServiceでセレクトボックスのオプションに保存したい

2024年6月9日日曜日

Apps Scriptでスプレッドシートのセルを結合して上揃えにしたい - Merge cells and align top in Spreadsheet using Apps Script


スプレッドシートのセルを結合して垂直方向の配置を設定するコードを試しました。
I tried Apps Script to merge cells and set the vertical alignment in a spreadsheet.


今回の例では、
In this example,

3列目の4行目と5行目のセルを結合します。
I will merge the cells in the 3rd column, 4th and 5th rows.

垂直方向の配置は「上」に設定します。
The vertical alignment will be set to "top."

結合したセルにvalueという値を入力します。
The merged cell will be filled with the value "value."



Apps Script


Code.gs
function mergeCellsInColumnU() {
const value = "value";
const sheet = SpreadsheetApp.getActiveSheet();
const startRow = 4;
const startCol = 3;
const numRows = 2;
const numCols = 1;
const range = sheet.getRange(startRow, startCol, numRows, numCols);
range.merge().setVerticalAlignment("top").setValue(value);
}


Tips

選択範囲で行単位、列単位で結合するメソッドもあったので試してみました。
I also tried using the methods that allow merging cells by row or column within a selected range.


mergeAcross()
function mergeCellsInColumnU() {
const value = "value";
const sheet = SpreadsheetApp.getActiveSheet();
const startRow = 4;
const startCol = 3;
const numRows = 2;
const numCols = 3;
const range = sheet.getRange(startRow, startCol, numRows, numCols);
range.mergeAcross().setVerticalAlignment("top").setValue(value);
}



mergeVertically()
function mergeCellsInColumnU() {
const value = "value";
const sheet = SpreadsheetApp.getActiveSheet();
const startRow = 4;
const startCol = 3;
const numRows = 2;
const numCols = 3;
const range = sheet.getRange(startRow, startCol, numRows, numCols);
range.mergeVertically().setVerticalAlignment("top").setValue(value);
}


Reference

Class Range > merge()

Class Range > mergeAcross()

Class Range > mergeVertically()

2024年6月8日土曜日

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


以下のリンク先では [ ] を目印にして文字色と背景色を変更しました。
In the following link, the text color and background color are changed using square brackets [] as markers.


今回は、Google Slidesにダイアログを表示して、入力した単語の文字色と背景色を変更するコードです。
This time, I'm trying a code that displays a dialog in Google Slides to change the text color and background color of a specified word.




Procedures


3行2列の表を用意して、2行目2列目にテキストを入力しておきます。
Prepare a table with 3 rows and 2 columns, and enter text in the second row and second column.


今回の例で使うテキスト
The text used in this example.

Trying to write a Google Apps Script that displays a dialog in Google Slides to highlight specific words within a table.


今回の例では、 highlight とwords の単語を対象にします。
In this example, the target words are "highlight" and "words."


Code.gs の modalessTemplate() を実行すると、ダイアログが表示されます。
After executing modalessTemplate() in Code.gs, a dialog will be displayed.


ダイアログに highlight と words を改行で区切って入力します。
Enter "highlight" and "words" in the dialog, separated by a newline.


表を選択してダイアログのsubmitボタンをクリックすると、文字色と背景色が変わります。



Apps Script


Code.gs
function modalessTemplate() {
const htmlOutput = HtmlService
.createTemplateFromFile("index")
.evaluate()
.setWidth(240)
.setHeight(240);
SlidesApp.getUi().showModelessDialog(htmlOutput, "MyGUI");
}

function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

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

function boldColorTargetWords(values) {
const table = getSelectedTable();
const row = 1;
const col = 1;
const cell = table.getCell(row, col);

const textRange = cell.getText();
let text = textRange.asString();
cell.getText().setText(text);
for (let i = 0; i < values.length; i++) {
const value = values[i];
const startIndex = text.indexOf(value);
const endIndex = startIndex + value.length;
const textStyle = textRange.getRange(startIndex, endIndex).getTextStyle();
textStyle.setBold(true);
textStyle.setForegroundColor('#FFFFFF'); // white
textRange.getRange(startIndex, endIndex).getTextStyle().setBackgroundColor('#000000'); // black
}
}


index.html
<!DOCTYPE html>
<html>
<head>
<?!= include("css"); ?>
</head>
<body>
<textarea id="words"></textarea>
<br>
<button id="submit">submit</button>
<?!= include("javascript"); ?>
</body>
</html>


css.html
<style>
#words {
font-size: 18px;
width: 90vw;
height: 70vh;
}
</style>


javascript.html
<script>
function elem(id) {
return document.getElementById(id);
}

elem("words").addEventListener("keyup", function () { inputKeyup("words") });
elem("submit").addEventListener("click", submitClicked);

function inputKeyup(id) {
elem(id).value = elem(id).value.replace(/"/g, "");
}

function submitClicked() {
const words = elem("words").value.trim().split("\n");
google.script.run.boldColorTargetWords(words);
}
</script>


Reference

Google Slidesの表内の指定文字の文字色と背景色を変えたい - Set the text color and background color within a table in 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 に課題が上がっていることが...