简体   繁体   English

合并Google Apps脚本中的两个变量

[英]Merging two variables in google apps script

function f(column) {
    var i = 4;
}

I want to merge the "column" and "i" variable so I can use it as input in the spreadsheet function getRange(); 我想合并“ column”和“ i”变量,以便可以将其用作电子表格函数getRange()中的输入;

Is there a simple way to do this? 有没有简单的方法可以做到这一点?

Yup, there is a pretty simple way to do that: I'm guessing if column="A" and as i=4, you want to set something into A4 cell, then do like this: 是的,有一种非常简单的方法可以做到这一点:我猜是否column =“ A”且由于i = 4,您想在A4单元格中设置一些内容,然后执行以下操作:

function f(column)
{
  var i = 4;
  SpreadsheetApp.getActiveSpreadsheet().getRange(column+i).setValue("Hello World");
}

Here, getRange() is accepting input value as "A4" or a1Notation. 在这里, getRange()接受输入值作为“ A4”或a1Notation。

I'm guessing that you want to use i as an offset along with column. 我猜想您想将i与列一起用作偏移量。

If so then 如果是这样

function f(column) {
    var i = 4;
    SpreadsheetApp.getActiveSheet().getRange("A1").offset(0, column + i, 1, 1);
}

would return a single cell, 4 + column to the right of A1. 将返回单个单元格,即A1右侧的4 +列。

暂无
暂无

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

相关问题 javascript(Google Apps脚本)声明变量 - javascript (google apps script) declaring variables Google Apps脚本,将两个(变量)2个“变量”或“数组”从code.gs传递给index.html / Javascript - Google apps script, pass (two) 2 “variables” or “array” from code.gs to index.html / Javascript 将 Google Sheet 数据合并到 Google Doc 模板的 Google Apps 脚本在第一行数据之后没有迭代 - Google Apps Script of merging Google Sheet data to Google Doc template is not iterating after the 1st row of data 如何判断Google Spreadsheet的Google Apps脚本中两个单元格是否相等 - How to tell if two cells are equal in Google Apps Script for Google Spreadsheet 如何在 Google Apps Script 中的 javascript 中引用 HtmlTemplate 变量 - How to reference HtmlTemplate variables in javascript in Google Apps Script 在全局范围内调用变量并在 Google 应用程序脚本中进行比较 - Calling variables at global scope and comparing it in Google apps script 在 Google Apps 脚本中通过引用在函数之间传递变量 - Passing variables between functions by reference in Google Apps Script 在 forEach 循环中使用 onclick 将变量传递给函数 - Google Apps Script - passing variables to a function with onclick in a forEach loop - Google Apps Script 从Google Apps脚本中的变量中添加数字变得奇怪 - Add numbers from variables in Google Apps Script going strange Apps 脚本中的全局变量 - Global Variables in Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM