我的代码返回正确的行(我认为),但对错误的行进行了写入写入Google Sheets脚本

时间:2018-10-17 15:39:48

标签: google-apps-script google-sheets

我正在尝试:

  • 在名为“罚分”的工作表上找到行号'PENALTY LINEUP ENTRY'!B10中单元格的值

  • 将该人“ PENALTY LINEUP ENTRY'!C10:J11”的数据复制到“罚款”表上的相邻单元格中。

问题是数据被写入错误的行,我不知道为什么。

这是我的电子表格: https://docs.google.com/spreadsheets/d/1aKcfX4u91aYFMPMOJBSlx92JmhRGH3MeVjLenxbEtAw/edit?usp=sharing

下面是我的代码:

function next_jam() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheetByName('PENALTY LINEUP ENTRY');
  var Psheet = ss.getSheetByName('Penalties');
  var Jam = sheet.getRange('D5');
  var JamValue = Jam.getValue();
  var Period = sheet.getRange('D2').getValue();
  var H_J =sheet.getRange('B10').getValue();
  var H_P =sheet.getRange('B13').getValue();
  var H_B1 =sheet.getRange('B16').getValue();
  var H_B2 =sheet.getRange('B19').getValue();
  var H_B3 =sheet.getRange('B22').getValue();
  var A_J =sheet.getRange('N10').getValue();
  var A_P =sheet.getRange('N13').getValue();
  var A_B1 =sheet.getRange('N16').getValue();
  var A_B2 =sheet.getRange('N19').getValue();
  var A_B3 =sheet.getRange('N22').getValue();
  var H_Jp = sheet.getRange('C10:J11');
  var H_JpValues = H_Jp.getValues(); 
  var H_Pp = sheet.getRange('C13:J14');
  var H_PpValues = H_Pp.getValues(); 
  var H_B1p = sheet.getRange('C16:J17');
  var H_B1pValues = H_B1p.getValues(); 
  var H_B2p = sheet.getRange('C19:J20');
  var H_B2pValues = H_B2p.getValues(); 
  var H_B3p = sheet.getRange('C22:J23');
  var H_B3pValues = H_B3p.getValues();
  var A_Jp = sheet.getRange('O10:V11');
  var A_JpValues = A_Jp.getValues(); 
  var A_Pp = sheet.getRange('O13:V14');
  var A_PpValues = A_Pp.getValues(); 
  var A_B1p = sheet.getRange('O16:V17');
  var A_B1pValues = A_B1p.getValues(); 
  var A_B2p = sheet.getRange('O19:V20');
  var A_B2pValues = A_B2p.getValues(); 
  var A_B3p = sheet.getRange('O22:V32')
  var A_B3pValues = A_B3p.getValues();  
  var H_P1 = Psheet.getRange('A1:H43');
  var H_P2 = Psheet.getRange('AC1:AJ43');
  var A_P1 = Psheet.getRange('P1:W43');
  var A_P2 = Psheet.getRange('AR1:AY43');
  var H_P1values = H_P1.getValues();
  var H_P2values = H_P2.getValues();
  var A_P1values = A_P1.getValues();
  var A_P2values = A_P2.getValues();


//   var ss = SpreadsheetApp.getActiveSpreadsheet();
//   var sheet = ss.getSheetByName('PENALTY LINEUP ENTRY');
//   var Psheet = ss.getSheetByName('Penalties');
//   var Jam = sheet.getRange('E5').getValue();
//   var Period = sheet.getRange('E2').getValue();
//   var H_J =sheet.getRange('B10').getValue();
//   var H_Jp = sheet.getRange('C10:J11').getValues();
//   var H_P1 = Psheet.getRange('A4:H43');
//   var H_P1values = H_P1.getValues();
Logger.log('This is the CURRENT HOME JAMMER = '+H_J);
  for (var i = 0; i < 21; i++) {
    var row = "";
    for (var j = 0; j < 21; j++) {     
      if (H_P1values[i][j] == H_J && Period == 1) {
        row = H_P1values[i][j+1];

        Logger.log('This is the Row the HOME JAMMER is on = '+i); // This is your row number

0 个答案:

没有答案