Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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 什么是moveTo的漫游方法,可以使带有公式的移动单元格不受影响_Google Apps Script - Fatal编程技术网

Google apps script 什么是moveTo的漫游方法,可以使带有公式的移动单元格不受影响

Google apps script 什么是moveTo的漫游方法,可以使带有公式的移动单元格不受影响,google-apps-script,Google Apps Script,问题是,如果任何单元格包含公式,则在moveTo方法之后,公式不会更新其引用 //WORKING - MOVES VALUES FROM "A1:B.." TO "C+lastrow2".. function my4() { var thiss = SpreadsheetApp.getActiveSpreadsheet(); var thissSh1 = thiss.getSheetByName("Entry"); var lastrow1 = thissSh1.getLastRow

问题是,如果任何单元格包含公式,则在moveTo方法之后,公式不会更新其引用

//WORKING - MOVES VALUES FROM "A1:B.." TO "C+lastrow2"..
function my4() {
  var thiss = SpreadsheetApp.getActiveSpreadsheet();
  var thissSh1 = thiss.getSheetByName("Entry");
  var lastrow1 = thissSh1.getLastRow()+1;
  var range = thissSh1.getRange("A1:A"+lastrow1).getValues();
  for(var i in range){
  source = thissSh1.getRange("A1:B1").offset(i, 0);
  dest = thissSh1.getRange("C"+lastrow1+":D"+lastrow1).offset(0, i*2);
  source.moveTo(dest);
  }
}
下面是我正在处理的代码,除了更新单元格引用外,它还完成了其他工作

//WORKING - MOVES VALUES FROM "A1:B.." TO "C+lastrow2"..
function my4() {
  var thiss = SpreadsheetApp.getActiveSpreadsheet();
  var thissSh1 = thiss.getSheetByName("Entry");
  var lastrow1 = thissSh1.getLastRow()+1;
  var range = thissSh1.getRange("A1:A"+lastrow1).getValues();
  for(var i in range){
  source = thissSh1.getRange("A1:B1").offset(i, 0);
  dest = thissSh1.getRange("C"+lastrow1+":D"+lastrow1).offset(0, i*2);
  source.moveTo(dest);
  }
}

文档清楚地说明了格式和值是复制的。它没有提到公式

:从该范围剪切并粘贴(格式和值)到目标范围

显然,它将公式视为内容-如果它将其更新为通过在电子表格中拖放移动范围,那将非常好

自2011年以来,这方面一直存在一个悬而未决的问题:

:在电子表格中移动范围应更新引用该范围的公式

启动它以接收更新

moveTo()
还有几个其他问题值得注意:

:注释未移动或复制w r.moveTo或r.copyTo

:Range.moveTo()无法正确处理重叠的源和目标范围

变通办法 使用
getFormulas()
从原始范围检索公式,遍历并转置所有公式,然后使用
setFormulas()
将它们放入新范围

听起来很简单,但事实并非如此。在每个公式中,您都需要标识单元格引用,确定它们是否受到移动的影响,如果受到影响,则进行更改。考虑到细胞或范围可以用多种方式描述,仅仅识别它们是很困难的

还需要考虑错误情况:跨越移动区域的范围如何?如果你最终创建了循环引用,那会破坏你的电子表格


我认为,你可以创建一个典型的双循环函数来移动和转置一个简单的公式子集。但是对于一个通用的解决方案,我想我们正在等待谷歌。

谢谢你的反馈!我想出了一个解决办法,我不知道如何解决,因为我几天前刚刚启动了谷歌应用程序脚本

可能的解决方法 1.为必须移动的每个单元格生成唯一的区域名称。 2.用范围名称替换公式中的引用。 3.移动第一个单元格。保留对其他单元格的引用(我对此进行了测试)。但是,其他单元格现在将引用移动单元格的前一个位置,因此必须删除旧单元格的名称,而改为命名新位置。 4.对范围内的每个单元格执行相同的操作

你认为谷歌应用程序脚本可行吗

最好的