code.gs
function main() {
//--------- Setup Parameter ---------//
var sheetid = "1--------------------------------w";
var notifyToken = "L--------------------------------Z";
var ssName = "เดินทาง";
var ssChart1 = "เดินทาง";
// var ssChart2 = "ชื่อชีทที่เก็บข้อมูกราฟเราต้องการจะส่งไปเป็นรูป";
// ------------------------------------//
var ss = SpreadsheetApp.openById(sheetid).getSheetByName(ssName);
var msg1;
var msg;
// --------- Your Message Go here - 1 --------//
msg1 = " " +(ss.getRange('A1').getValue())+" " + "\n" +
" " +(ss.getRange('A2').getValue())+" " +(ss.getRange('B2').getValue())+" คน " +(ss.getRange('A3').getValue())+" " +(ss.getRange('B3').getValue())+" คน " + "\n" +
"รวม" +(ss.getRange('C2').getValue()) +" คน " +"\n" ;
// ------------------------------------//
// --------- Your Message Go here - 2 --------//
var ssName2 = "ห้องพัก";
var ssChart2 = "ห้องพัก";
var ss = SpreadsheetApp.openById(sheetid).getSheetByName(ssName2);
msg2 = " " +(ss.getRange('A1').getValue())+" " + "\n" +
" " +(ss.getRange('A2').getValue())+" คน จำนวน " +(ss.getRange('B2').getValue())+" ห้อง " +(ss.getRange('A3').getValue())+" คน จำนวน " +(ss.getRange('B3').getValue())+" ห้อง " + "\n" +
" รวม " +(ss.getRange('C2').getValue()) +" ห้อง " +"\n" ;
// ------------------------------------//
// --------- Your Message Go here - 3 --------//
var ssName3 = "กลุ่มอายุจ่ายเงิน";
var ssChart3 = "กลุ่มอายุจ่ายเงิน";
var ssChart4 = "กลุ่มอายุจ่ายเงิน";
var ss = SpreadsheetApp.openById(sheetid).getSheetByName(ssName3);
msg3 = " " +(ss.getRange('A1').getValue())+" " + "\n" +
// " " +(ss.getRange('A2').getValue())+" คน จำนวน " +(ss.getRange('B2').getValue())+
" อายุ" +(ss.getRange('A3').getValue())+" จำนวน " +(ss.getRange('B3').getValue())+" คน " + "\n" +
" อายุ" +(ss.getRange('A4').getValue())+" จำนวน " +(ss.getRange('B4').getValue())+" คน " + "\n" +
" อายุ" +(ss.getRange('A5').getValue())+" จำนวน " +(ss.getRange('B5').getValue())+" คน " + "\n" +
" อายุ" +(ss.getRange('A6').getValue())+" จำนวน " +(ss.getRange('B6').getValue())+" คน " + "\n" +
" รวม " +(ss.getRange('B1').getValue()) +" คน " +"\n" ;
msg4 = " " +(ss.getRange('A1').getValue())+" " + "\n" +
// " " +(ss.getRange('A2').getValue())+" คน จำนวน " +(ss.getRange('B2').getValue())+
" อายุ" + (ss.getRange('C3').getValue()) +" จำนวน " +(ss.getRange('D3').getValue())+" คน " + "\n" +
" อายุ" + (ss.getRange('C4').getValue()) +" จำนวน " +(ss.getRange('D4').getValue())+" คน " + "\n" +
" อายุ" + (ss.getRange('C5').getValue())+" จำนวน " +(ss.getRange('D5').getValue())+" คน " + "\n" +
" อายุ" + (ss.getRange('C6').getValue()) +" จำนวน " +(ss.getRange('D6').getValue())+" คน " + "\n" +
" รวม " +(ss.getRange('B1').getValue()) +" คน " +"\n" ;
// ------------------------------------//
// --------- Your Message Go here - 5 --------//
var ssName5 = "เพศ";
var ssChart5 = "เพศ";
var ss = SpreadsheetApp.openById(sheetid).getSheetByName(ssName5);
msg5 = " " +(ss.getRange('A1').getValue())+" " + "\n" +
" " +(ss.getRange('A2').getValue())+"จำนวน " +(ss.getRange('B2').getValue())+" คน " +(ss.getRange('A3').getValue())+"จำนวน " +(ss.getRange('B3').getValue())+" คน " + "\n" +
" รวม " +(ss.getRange('C2').getValue()) +" คน " +"\n" ;
// ------------------------------------//
// --------- Sending Message and Chart to LineNotify - 1 --------//
msg = {
message: msg1,
imageFile: getChart(sheetid,ssChart1,0),
}
sendLineNotify(msg, notifyToken);
// --------- Sending Message and Chart to LineNotify - 2 --------//
msg = {
message: msg2,
imageFile: getChart(sheetid,ssChart2,0),
}
sendLineNotify(msg, notifyToken);
// --------- Sending Message and Chart to LineNotify - 3 --------//
msg = {
message: msg3,
imageFile: getChart(sheetid,ssChart3,0),
}
sendLineNotify(msg, notifyToken);
msg = {
message: msg4,
imageFile: getChart(sheetid,ssChart4,1),
}
sendLineNotify(msg, notifyToken);
msg = {
message: msg5,
imageFile: getChart(sheetid,ssChart5,0),
}
sendLineNotify(msg, notifyToken);
}
function sendLineNotify(messages, accessToken) {
const lineNotifyEndPoint = "https://notify-api.line.me/api/notify";
const options = {
"headers": { "Authorization": "Bearer " + accessToken },
"method": 'post',
"payload": messages,
};
try {
UrlFetchApp.fetch(lineNotifyEndPoint, options);
} catch (error) {
Logger.log(error.name + ":" + error.message);
return;
}
}
function formatDollar(num) {
var p = num.toFixed(2).split(".");
return "฿" + p[0].split("").reverse().reduce(function(acc, num, i, orig) {
return num=="-" ? acc : num + (i && !(i % 3) ? "," : "") + acc;
}, "") + "." + p[1];
}
function getChart(ssid,name,pos) {
var ss = SpreadsheetApp.openById(ssid).getSheetByName(name);
var chart = ss.getCharts()[pos].getBlob().getAs("image/png");
return chart;
}
function DateConvert(date) {
var yyyy = date.getFullYear().toString();
var mm = (date.getMonth()+1).toString(); // getMonth() is zero-based
var dd = date.getDate().toString();
return (dd[1]?dd:"0"+dd[0]) + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + yyyy;
};
ไม่มีความคิดเห็น:
แสดงความคิดเห็น
หมายเหตุ: มีเพียงสมาชิกของบล็อกนี้เท่านั้นที่สามารถแสดงความคิดเห็น