简体   繁体   English

如何使用脚本访问 Google 工作表中选定单元格旁边的单元格?

[英]How to access the cell next to the selected cell in Google sheet using script?

I just started exploring google sheets and javascript and I wrote a function which prompts the user to type a string which is entered into the selected cell.我刚开始探索谷歌表格和 javascript,我写了一个 function,它提示用户输入一个输入到所选单元格中的字符串。 I'm accessing the current cell using SpreadsheetApp.getActiveSheet().getActiveCell() and setting the value using.setValue().我正在使用 SpreadsheetApp.getActiveSheet().getActiveCell() 访问当前单元格并使用.setValue() 设置值。

Now I made another prompt and I want to put this value in the cell next to the selected cell (same row but column+1).现在我做了另一个提示,我想把这个值放在所选单元格旁边的单元格中(同一行但列+1)。 How do I access the current cells row and column positions and then increment the col with 1?如何访问当前单元格的行和列位置,然后将 col 增加 1?

In pseudo code im thinking something like this;在伪代码中,我在想这样的事情; ActiveCell[row][column+1] = string input from prompt2 ActiveCell[row][column+1] = 来自 prompt2 的字符串输入

Try using offset to specify offset:尝试使用offset来指定偏移量:

let cell = SpreadsheetApp.getActiveSheet().getActiveCell();

// update cell to the right
cell.offset(0, 1).setValue("upd");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM