如何在Google电子表格中使用Google脚本获取邻近单元格的值? [英] How do I get the value from an adjacent cell using Google Script in a Google Spreadsheet?

查看:135
本文介绍了如何在Google电子表格中使用Google脚本获取邻近单元格的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很抱歉,如果之前有人问过这个问题,但我已经找过一个例子,不幸的是我无法找到答案,因此我在这里问。



如果我在Google Spreadsheet中有自定义函数,如果内容是动态生成的,我如何获取单元格的值。当它是一个固定的值时,我可以得到它的值,但当它是动态的时候,我可以得到这个值。 下面是一个获取相邻单元格值的例子无论它是动态的(使用函数创建的或它是一个单位值)

$ p $函数getAdjacentValue(){
var range = SpreadsheetApp.getActiveRange();
var col = range.getColumn();
var row = range.getRow();
var range2 = SpreadsheetApp.getActiveSheet()。getRange(row,col + 1);
return range2.getValue();
}


I apologise if this has been asked before but I've looked for an example and unfortunately I'm unable to find an answer hence why I'm asking here.

If I have a custom function in a Google Spreadsheet how do I get the value of a cell if the contents are dynamically generated. I can get the value when it's a fixed value but not when it's dynamic.

解决方案

Here's an example of getting the adjacent cell's value whether it's dynamic (created with a function or it's a flat value)

function getAdjacentValue() {
  var range = SpreadsheetApp.getActiveRange();
  var col = range.getColumn();
  var row = range.getRow();
  var range2 = SpreadsheetApp.getActiveSheet().getRange(row,col+1);
  return range2.getValue();
}

这篇关于如何在Google电子表格中使用Google脚本获取邻近单元格的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆