Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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
Javascript 如何通过匹配其他[Sheet]来替换[cell]?_Javascript_Google Apps Script_Google Sheets - Fatal编程技术网

Javascript 如何通过匹配其他[Sheet]来替换[cell]?

Javascript 如何通过匹配其他[Sheet]来替换[cell]?,javascript,google-apps-script,google-sheets,Javascript,Google Apps Script,Google Sheets,我想将sheet1 col A与sheet2 Colum B匹配 如果是1!A:A=2!B:B 将活页1 C:C更换为活页2!D:D 我想在谷歌电子表格上这样做,但我对java知之甚少。怎么做 function replaceCCWithDD(){ // in this example sheet, the function will replace sheet1 C:C from Sheet2! D:D if Sheet1! A:A matched with Sheet2! B:B var

我想将sheet1 col A与sheet2 Colum B匹配

如果是1!A:A=2!B:B

将活页1 C:C更换为活页2!D:D

我想在谷歌电子表格上这样做,但我对java知之甚少。怎么做

function replaceCCWithDD(){ // in this example sheet, the function will replace sheet1 C:C from Sheet2! D:D if Sheet1! A:A matched with Sheet2! B:B

var sh1 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet1');
var sh2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
试试下面的代码:

function myFunction() {
var sh1 = SpreadsheetApp.openById("0AjCcE3eIeB3pdFNFTUdQN1M5Rm4wOU5SSzlXb2Utc2c").getSheetByName('sheet1');
var sh2 = SpreadsheetApp.openById("0AjCcE3eIeB3pdFNFTUdQN1M5Rm4wOU5SSzlXb2Utc2c").getSheetByName('sheet2');

var colA = sh1.getDataRange().getValues();
var colB = sh2.getDataRange().getValues();

for(var x in colA) {    
    Logger.log(x < colB.length && colA[x][0] == colB[x][1]);
    if(x < colB.length && colA[x][0] == colB[x][1]) {         
     colA[x][2] = colB[x][3];
    }
  }  
  sh1.getDataRange().setValues(colA);
}
函数myFunction(){
var sh1=SpreadsheetApp.openById(“0ajcce3eieb3pdnftudqn1m5rm4wou5sszlxb2utc2c”)。getSheetByName(“sheet1”);
var sh2=SpreadsheetApp.openById(“0ajcce3eieb3pdnftudqn1m5rm4wou5sszlxb2utc2c”)。getSheetByName(“sheet2”);
var colA=sh1.getDataRange().getValues();
var colB=sh2.getDataRange().getValues();
对于(可乐中的var x){
Logger.log(x

实时版本。

这是您的全部代码吗?你的“如果”条件在哪里?如果不是我的代码。。我不知道如何在java/Googles应用程序脚本中编写,我刚刚开始阅读Google的应用程序脚本。谢谢@br araujo。我有一个错误:“范围的坐标或尺寸无效。(第7行,文件“代码”)这里的“X”是什么意思?X是colA数组的索引。请检查B是否具有相同的长度。请查看编辑的代码太棒了!非常感谢!太棒了!太棒了!:-)