Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 需要找到一种方法,使数据输入在特定行之后的特定列中开始_Google Apps Script_Google Sheets - Fatal编程技术网

Google apps script 需要找到一种方法,使数据输入在特定行之后的特定列中开始

Google apps script 需要找到一种方法,使数据输入在特定行之后的特定列中开始,google-apps-script,google-sheets,Google Apps Script,Google Sheets,这是我的剧本: function CopyRange() { var sss = SpreadsheetApp.openById('1EA2F99W1lpgTzX3zoTNpzuEXWh-mDkvo9UyZC4kDNtQ'); //replace with source ID var ss = sss.getSheetByName('UKG-A'); //replace with source Sheet tab name var range = ss.getRange('G4:K4');

这是我的剧本:

function CopyRange() {
 var sss = SpreadsheetApp.openById('1EA2F99W1lpgTzX3zoTNpzuEXWh-mDkvo9UyZC4kDNtQ'); //replace with source ID
 var ss = sss.getSheetByName('UKG-A'); //replace with source Sheet tab name
 var range = ss.getRange('G4:K4'); //assign the range you want to copy
 var data = range.getValues();

 var tss = SpreadsheetApp.openById('1EA2F99W1lpgTzX3zoTNpzuEXWh-mDkvo9UyZC4kDNtQ'); //replace with destination ID
 var ts = tss.getSheetByName('UKG-A'); //replace with destination Sheet tab name

 ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data); //you will need to define the size of the copied data see getRange()
 

}
我在A列到M列的第1行到第33行之间有一些数据。我想在第6行之后的O列中启动数据条目,而不对A列到M列中的数据产生影响。是否有类似的情况,我可以找到O列的最后一行,从第6行开始,+1,就像我的原始脚本一样。 谢谢。

我用这个:

function getColumnHeight(col,sh,ss){
  var ss=ss||SpreadsheetApp.getActive();
  var sh=sh||ss.getActiveSheet();
  var col=col||sh.getActiveCell().getColumn();
  const rcA=sh.getRange(1,col,sh.getLastRow(),1).getValues().reverse()
  let s=0;
  for(let i=0;i<rcA.length;i++) {
    if(rcA[i][0].toString().length==0) {
      s++;
    }else{
      break;
    }
  }
  return rcA.length-s;
}
函数getColumnHeight(col、sh、ss){ var ss=ss | | SpreadsheetApp.getActive(); var sh=sh | | ss.getActiveSheet(); var col=col | | sh.getActiveCell().getColumn(); const rcA=sh.getRange(1,col,sh.getLastRow(),1).getValues().reverse() 设s=0; 对于(设i=0;i我使用:

function getColumnHeight(col,sh,ss){
  var ss=ss||SpreadsheetApp.getActive();
  var sh=sh||ss.getActiveSheet();
  var col=col||sh.getActiveCell().getColumn();
  const rcA=sh.getRange(1,col,sh.getLastRow(),1).getValues().reverse()
  let s=0;
  for(let i=0;i<rcA.length;i++) {
    if(rcA[i][0].toString().length==0) {
      s++;
    }else{
      break;
    }
  }
  return rcA.length-s;
}
函数getColumnHeight(col、sh、ss){ var ss=ss | | SpreadsheetApp.getActive(); var sh=sh | | ss.getActiveSheet(); var col=col | | sh.getActiveCell().getColumn(); const rcA=sh.getRange(1,col,sh.getLastRow(),1).getValues().reverse() 设s=0; 对于(设i=0;隔离: 其思想是在O列中找到第一个非空值的值,从表的底部开始,一直到第6行

替换:

ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data);
const start_row = 6;
const col15 = ts.getRange(start_row,15,ts.getLastRow()).getValues().flat();
const index = col15.reverse().findIndex(c=>c!='');
const size = index>-1 ? ts.getLastRow() - index + start_row : start_row;
ts.getRange(size,15,1,5).setValues(data); 
与:

ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data);
const start_row = 6;
const col15 = ts.getRange(start_row,15,ts.getLastRow()).getValues().flat();
const index = col15.reverse().findIndex(c=>c!='');
const size = index>-1 ? ts.getLastRow() - index + start_row : start_row;
ts.getRange(size,15,1,5).setValues(data); 
参考文献:

ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data);
const start_row = 6;
const col15 = ts.getRange(start_row,15,ts.getLastRow()).getValues().flat();
const index = col15.reverse().findIndex(c=>c!='');
const size = index>-1 ? ts.getLastRow() - index + start_row : start_row;
ts.getRange(size,15,1,5).setValues(data); 
解决方案: 其思想是在O列中找到第一个非空值的值,从表的底部开始,一直到第6行

替换:

ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data);
const start_row = 6;
const col15 = ts.getRange(start_row,15,ts.getLastRow()).getValues().flat();
const index = col15.reverse().findIndex(c=>c!='');
const size = index>-1 ? ts.getLastRow() - index + start_row : start_row;
ts.getRange(size,15,1,5).setValues(data); 
与:

ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data);
const start_row = 6;
const col15 = ts.getRange(start_row,15,ts.getLastRow()).getValues().flat();
const index = col15.reverse().findIndex(c=>c!='');
const size = index>-1 ? ts.getLastRow() - index + start_row : start_row;
ts.getRange(size,15,1,5).setValues(data); 
参考文献:

ts.getRange(ts.getLastRow()+1,15,1,5).setValues(data);
const start_row = 6;
const col15 = ts.getRange(start_row,15,ts.getLastRow()).getValues().flat();
const index = col15.reverse().findIndex(c=>c!='');
const size = index>-1 ? ts.getLastRow() - index + start_row : start_row;
ts.getRange(size,15,1,5).setValues(data);