[英]Missing ) after argument list when trying to use importrange in app script
I'm trying to use google app script in google sheets to set a formula to importrange. 我正在尝试使用Google表格中的Google App脚本将公式设置为importrange。 I have the following code: 我有以下代码:
SpreadsheetApp.getActiveSheet().getCurrentCell().setFormulaR1C1('=IMPORTRANGE("https://docs.google.com/spreadsheets/d/blahblah","Completed Work!B5:N")');
My problem is when I try to make the code take an argument for the URL so when I say: 我的问题是,当我尝试使代码接受URL的参数时,我说:
SpreadsheetApp.getActiveSheet().getCurrentCell().setFormulaR1C1('=IMPORTRANGE('URL',"Completed Work!B5:N")');
When I try to run my function using: 当我尝试使用以下命令运行函数时:
myfunction("https://docs.google.com/spreadsheets/d/blahblah","Completed Work!B5:N")
I get a Missing ) after argument list error, how would I go about fixing the second formula so URL can be passed as an argument of the function? 参数列表错误后出现Missing),我将如何解决第二个公式,以便可以将URL作为函数的参数传递?
Thanks! 谢谢!
Use the JavaScript string concatenation operator +
使用JavaScript字符串串联运算符+
You have to learn about string concatenation on JavaScript. 您必须了解JavaScript上的字符串连接。
From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String (follow the link to see the inline links) 从https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String (点击链接查看内联链接)
Strings are useful for holding data that can be represented in text form. 字符串对于保存可以以文本形式表示的数据很有用。 Some of the most-used operations on strings are to check their length, to build and concatenate them using the
+
and+=
string operators, checking for the existence or location of substrings with theindexOf()
method, or extracting substrings with thesubstring()
method. 对字符串最常用的一些操作是检查它们的长度,使用+
和+=
字符串运算符来构建和连接它们,使用indexOf()
方法检查子字符串的存在或位置,或者使用substring()
提取子substring()
方法。
Instead of 代替
'=IMPORTRANGE('URL',"Completed Work!B5:N")'
use 采用
'=IMPORTRANGE("' + URL + '","Completed Work!B5:N")'
NOTE: Pleas note the use of "
to doble quote enclose the value of URL as it's required by IMPORTRANGE. 注意:请注意使用"
来引号括住IMPORTRANGE要求的URL值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.