简体   繁体   English

Google Sheets Script:在 setFormula() 中引用不同的工作表

[英]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.

相关问题 使用 Google Sheets 中的脚本设置公式 - setFormula by using script in Google Sheets В Google Sheets в Scripts не срабатывает setFormula c многочисленными ЕСЛИ - В Google Sheets в Scripts не срабатывает setFormula c многочисленными ЕСЛИ 从下拉应用程序脚本将行移动到谷歌工作表中的不同工作表 - Moving row to different sheet in google sheets from dropdown app script Google Script SetFormula转义引号 - Google Script SetFormula escaping quotes Google Apps 脚本集公式 function - Google Apps Script setFormula function 脚本编辑器中的setFormula(),其中公式引用的工作表中有空格 - setFormula() in script editor with spaces in sheets referenced by the formula 谷歌表格中“setformula”后的公式解析错误 - Formula parse error after “setformula” in google sheets Google Apps Script Q - 在表格中是否可以设置公式(SUM),其中要求和的单元格根据行而变化? - Google Apps Script Q - In Sheets is it possible to setFormula (SUM) where cells to sum change depending on row? 工作表单元格中的 Google Apps 脚本 setFormula() 遇到“#REF!” 使用 function doGet(e) 发出问题 - Google Apps Script setFormula() in sheet cell encounters “#REF!” issue by using function doGet(e) Google Apps 表中的 Simplify.setFormula 代码 - Simplify .setFormula code in Google Apps Sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM