Skip to content

Instantly share code, notes, and snippets.

@bathtimefish
Created June 7, 2013 04:11
Show Gist options
  • Save bathtimefish/5727019 to your computer and use it in GitHub Desktop.
Save bathtimefish/5727019 to your computer and use it in GitHub Desktop.
Google Apps Script スプレッドシートで特定の列セルに入力した文字に応じて対応する行の背景色を変更する。 TODOシートなどで「完了」を入力したらその行を自動的に完了の色にする。という感じで使う
/*
The MIT License (MIT)
Copyright (C) 2013, Masakazu Muraoka <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
Google Apps Script
スプレッドシートで特定の列セルに入力した文字に応じて対応する行の背景色を変更する。
TODOシートなどで「完了」を入力したらその行を自動的に完了の色にする。という感じで使う
*/
function onEdit(event)
{
var complete = '完了'; // 完了ステータスの文字
var pending = '保留'; // 保留ステータスの文字
var extend = '継承'; // 継承ステータスの文字
var keywordCol = 5; // 上記を入力する列
var columnStart = 1; // 背景色を変更する行の開始列
var columnNum = 8; // 背景色を変更する行の終端列
var range = event.source.getActiveRange();
var rowidx = range.getRow();
var sheet = event.source.getActiveSheet();
if( sheet.getRange(rowidx, keywordCol).getValue() == complete ){
sheet.getRange(rowidx, columnStart, 1, columnNum).setBackgroundColor('lightgray');
} else if( sheet.getRange(rowidx, keywordCol).getValue().indexOf(pending) != -1 ){
sheet.getRange(rowidx, columnStart, 1, columnNum).setBackgroundColor('#99cc99');
} else if( sheet.getRange(rowidx, keywordCol).getValue().indexOf(extend) != -1 ){
sheet.getRange(rowidx, columnStart, 1, columnNum).setBackgroundColor('#bbbbbb');
} else {
sheet.getRange(rowidx, columnStart, 1, columnNum).setBackgroundColor('white');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment