2016-06-20 11 views
0

値(たとえば1)のシート(名前:1)を分析し、別のシート(名前:2)の値。Googleスプレッドシートスクリプト - 値(1)の表を分析し、この値を持つ複数の行を別の表に投稿する

「の値を得た列F内のすべてのセルを検索(例1)。コピーの列A、E及びG(Fが1の場合)とシートの最後にそれを投稿2.

私のスクリプト。?。ただ実際には1つの結果を投稿、あなたが私を助けてもらえます私はちょうどループのいずれかの種類を取得いけないと思います、今それが行われます

function checkWS() { 
 
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 
 
    SpreadsheetApp.setActiveSheet(spreadsheet.getSheetByName("1")); 
 
    var sheet = spreadsheet.getActiveSheet(); 
 

 
    // figure out what the last row is 
 
    var lastRow = sheet.getLastRow(); 
 

 
    // the rows are indexed starting at 1, and the first row 
 
    // is the headers, so start with row 2 
 
    var startRow = 2; 
 

 
    // grab column 5 (the 'month left' column) 
 
    var range = sheet.getRange(2, 6, lastRow - startRow + 1, 1); 
 
    var numRows = range.getNumRows(); 
 
    var soll_values = range.getValues(); 
 

 
    // Now, grab the reminder name column 
 
    range = sheet.getRange(2, 1, lastRow - startRow + 1, 1); 
 
    var branch_values = range.getValues(); 
 

 
    // and the count column 
 
    range = sheet.getRange(2, 7, lastRow - startRow + 1, 1); 
 
    var count_values = range.getValues(); 
 

 
    var warning_count = 0; 
 
    var msg = ""; 
 

 
    // Loop over the days left values 
 
    for (var i = 0; i <= numRows - 1; i++) { 
 
    var soll = soll_values[i][0]; 
 
    if (soll == 1) { 
 
     // if it's exactly 1, do something with the data. 
 
     var name = branch_values[i][0]; 
 
     var count = count_values[i][0]; 
 

 
     warning_count++; 
 
    } 
 
    } 
 

 
    if (warning_count) { 
 
    var ss = SpreadsheetApp.openById("1vn4xTwdNk7E1Av4VNugtW6KWgZns2LzKS1lN1F6CTPw"); 
 
    var Tab = ss.getSheetByName('2'); 
 
    var lastRow = Tab.getLastRow(); 
 

 
    Tab.getRange(lastRow + 1, 1).setValue(name); 
 
    Tab.getRange(lastRow + 1, 5).setValue(count); 
 
    Tab.getRange(lastRow + 1, 10).setValue(new Date()); 
 

 
    SpreadsheetApp.flush(); 
 
    } 
 

 
}

答えて

0

私はほんの少しの手助け-coloumnで働いていました:

function checkWS() { 
    var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); 
    SpreadsheetApp.setActiveSheet(spreadsheet.getSheetByName("NAME")); 
    var sheet = spreadsheet.getActiveSheet(); 

    // figure out what the last row is 
    var lastRow = sheet.getLastRow(); 

    // the rows are indexed starting at 1, and the first row 
    // is the headers, so start with row 2 
    var startRow = 6; 

    // grab date (the 'month left' column) 
    var range = sheet.getRange(6, 54, lastRow - startRow + 1, 1); 
    var numRows = range.getNumRows(); 
    var soll_values = range.getValues(); 

    // Now, grab the branch column 
    range = sheet.getRange(6, 11, lastRow - startRow + 1, 1); 
    var branch_values = range.getValues(); 

    // and the count column 
    range = sheet.getRange(6, 49, lastRow - startRow + 1, 1); 
    var count_values = range.getValues(); 

    var warning_count = 0; 
    var msg = ""; 

    // Loop over the days left values 
    for (var i = 0; i <= numRows - 1; i++) { 
    var soll = soll_values[i][0]; 
    if (soll == 1) { 
     // if it's exactly 1, do something with the data. 
     var name = branch_values[i][0]; 
     var count = count_values[i][0]; 

     warning_count++; 

//  if (warning_count) { -> not needed 
     var ss = SpreadsheetApp.openById("ID"); 
     var Tab = ss.getSheetByName('NAME_other_ss'); 
     var lastRow = Tab.getLastRow(); 

     Tab.getRange(lastRow + 1, 10).setValue(name); 
     Tab.getRange(lastRow + 1, 14).setValue(count); 
     Tab.getRange(lastRow + 1, 20).setValue(new Date()); 

     SpreadsheetApp.flush(); 
//  } 
    } 
    } 



} 
関連する問題