0

我想分析一个工作表(名称:1)的值(例如 1),并将这些行中的一些值与该值一起发布到另一个工作表(名称:2)中。

“在 F 列中搜索所有获得值的单元格(例如 1)。复制 A、E 和 G 列(如果 F 为 1)并将其发布在第 2 页的末尾。

我的脚本实际上只是发布了一个结果。请你帮助我好吗?我想我只是没有得到任何循环?

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();
  }

}

4

1 回答 1

0

现在它完成了。我刚刚使用了一些帮助栏:

 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();
//      }
    }
  }



}
于 2016-06-28T11:58:47.830 回答