Google スプレッドシートにデータを送信する Google フォームを作成しました。特定の列の値に基づいて行を色分けしようとしていますが、問題ありません。ただし、onEdit 関数を使用していて、ユーザーがフォームを送信しても行の色が変わりません。行の色が変わるのは特定のセルを編集したときだけなので、 onEdit 関数です。技術的には編集であっても、Google はフォームの送信をスプレッドシートの「編集」として認識していないようです。関数をコピーして貼り付け、名前を onOpen に変更しようとしましたが、それも機能しません。ここで何が欠けていますか?以下にコードを掲載しました。お役に立てれば幸いです。また、私はスクリプト作成の初心者ですので、お手柔らかにお願いします ;)
// Color code rows based on the status of the ticket
function onEdit(e) {
if (e) {
var ss = e.source.getActiveSheet();
var r = e.source.getActiveRange();
// If you want to be specific
// do not work in first row
// do not work in other sheets except "Sheet1"
if (r.getRow() != 1 && ss.getName() == "Sheet1") {
// E.g. status column is 6th (F)
status = ss.getRange(r.getRow(), 6).getValue();
// Specify the range with which You want to highlight
// with some reading of API you can easily modify the range selection properties
// (e.g. to automatically select all columns)
rowRange = ss.getRange(r.getRow(),1,1,6);
// This changes row color
if (status == 'New') {
rowRange.setBackgroundColor("#f26c4f");
} else if (status == 'In Progress') {
rowRange.setBackgroundColor("#fff568");
} else if (status == 'Ordered') {
rowRange.setBackgroundColor("#68baff");
} else if (status == 'Completed') {
rowRange.setBackgroundColor("#a2e7a5");
// DEFAULT
} else if (status == '') {
rowRange.setBackgroundColor("#FFFFFF");
}
}
}
}