Skip to content

Instantly share code, notes, and snippets.

@pplog
Created July 21, 2019 01:39
Show Gist options
  • Save pplog/0a2ee6930c90b0067403bbf662f4fb30 to your computer and use it in GitHub Desktop.
Save pplog/0a2ee6930c90b0067403bbf662f4fb30 to your computer and use it in GitHub Desktop.
function checkCell() {
// スプレッドシートを指定
var spreadshseet = SpreadsheetApp.openById('***********')
var numSheets = spreadshseet.getNumSheets();
//チェックする文字列を定義
var reg = "NG【要確認】";
loop:
for(var sheetNo = 0; sheetNo <= numSheets-1; sheetNo++) {
SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[sheetNo];
var sheetName = SpreadsheetApp.getActiveSpreadsheet().getSheets()[sheetNo].getSheetName();
var range = sheet.getDataRange();
var values = range.getValues();
for (var i = 0; i < values.length; i++) {
var row = "";
for (var j = 0; j < values[i].length; j++) {
if (values[i][j]) {
row = row + values[i][j];
if (row.match(new RegExp(reg))) {
var messageBody = "<@U8LPZ1BBP>" + sheetName + "シートの" + i + "行目でセルの差異チェックがNGになってるよ";
sendSlackMessage(messageBody);
break loop;
}
}
}
}
}
}
function sendSlackMessage(message) {
var postUrl = 'https://hooks.slack.com/services/******';
var username = 'bot';
var icon = ':hatching_chick:';
var jsonData =
{
"username" : username,
"icon_emoji": icon,
"text" : message
};
var payload = JSON.stringify(jsonData);
var options =
{
"method" : "post",
"contentType" : "application/json",
"payload" : payload
};
UrlFetchApp.fetch(postUrl, options);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment