[英]Google Sheets Script: Referencing a different sheet in setFormula()
I'm writing a script in Google Sheets that enters in a formula which references data from a cell in a different sheet.我正在 Google Sheets 中编写一个脚本,该脚本输入一个公式,该公式引用来自不同工作表中单元格的数据。 (Ex: ='Monthly Expenses'!A1).
(例如:='每月费用'!A1)。
I made variables for "name" and "cell", so the line of code looks like this:我为“name”和“cell”创建了变量,所以这行代码如下所示:
cell.setFormula(name+"!A1");
It works when the sheet name is just one word, but when two or more words are added, the single quotes are obviously required, and I can't seem to add them to the setFormula and get it to work.当工作表名称只有一个词时它起作用,但是当添加两个或更多词时,显然需要单引号,而且我似乎无法将它们添加到 setFormula 并使其工作。 Any help is appreciated!
任何帮助表示赞赏!
你应该使用这个:
cell.setFormula("'" + name + "'!" + "A1");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.