しぇえt
城ヶ崎姫子
05a10a1bee
通報 ...
カスタムUI(サイドバー)の表示
コード.gs
function onOpen() {
SpreadsheetApp.getUi()
.createMenu('カスタムツール') // メニューバーの新しい項目名
.addItem('カウンターを開く', 'showSidebar') // メニュー項目とその実行関数
.addToUi();
}
function showSidebar() {
const html = HtmlService.createTemplateFromFile('Sidebar') // HTMLファイル名(次で作成)
.evaluate()
.setTitle('カウントアップツール');
SpreadsheetApp.getUi().showSidebar(html);
}
function incrementA2() {
// 対象シート名(必要に応じて変更)
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('シート1');
if (!sheet) return;
const targetCell = sheet.getRange('A2');
let currentValue = targetCell.getValue();
// 値が数値でなければ0として扱う
if (typeof currentValue !== 'number' || currentValue === '') {
currentValue = 0;
}
// 値を+1して書き込む
targetCell.setValue(currentValue + 1);
}
A2 カウンター
クリックすると「シート1」のA2セルに +1 が実行されます。
カウントアップを実行
は?
Htmlはれんのかめんどくせえw
リンク