var spreadsheets = SpreadsheetApp.openById(spreadSheetId);
//A2にAlexaの行数(次に差し込まれる場所)、B2にGlideApp用リスト行数(次に差し込まれる場所)
var settings_spreadsheet = spreadsheets.getSheetByName("Setting");
var alexa_spreadsheet = spreadsheets.getSheetByName("AlexaShoppingList");
var shopppinglist_spreadsheet = spreadsheets.getSheetByName("ShoppingList");
//Alexaから追加の買い物が通知されたら、GlideApp用のシートに転記する(5分おきの定期実行)
function copyAlexa2List(){
//二次元配列に
var alexa_data = alexa_spreadsheet.getRange(1,1,alexa_spreadsheet.getLastRow(),3).getValues();
alexa_start_cell = settings_spreadsheet.getRange(2,1).getValue()
shoppinglist_start_cell = settings_spreadsheet.getRange(2,2).getValue()
var i = -1
for (var j = alexa_start_cell; j<=alexa_spreadsheet.getLastRow() ; j++){
shopppinglist_spreadsheet.getRange(shoppinglist_start_cell + i + 1,1).setValue(alexa_data[alexa_start_cell + i][2])
i++;
}
settings_spreadsheet.getRange(2,1).setValue(alexa_start_cell + i + 1)
settings_spreadsheet.getRange(2,2).setValue(shoppinglist_start_cell + i + 1)
}
//GlideApp用の買い物リストでチェックがついたものをクリアする(1日1回)
function delShoppingList(){
var data = []
for (var j = 2; j<=shopppinglist_spreadsheet.getLastRow() ; j++){
if (!shopppinglist_spreadsheet.getRange(j,2).getValue()){
data.push(shopppinglist_spreadsheet.getRange(j,1).getValue());
}
shopppinglist_spreadsheet.getRange(j,1).setValue("")
shopppinglist_spreadsheet.getRange(j,2).setValue("")
}
for (var i = 0; i<data.length; i++){
shopppinglist_spreadsheet.getRange(i+2,1).setValue(data[i]);
}
settings_spreadsheet.getRange(2,2).setValue(data.length + 2)
}