[英]Google Spreadsheet: How to name a range using Google Apps Script
I am using the following code to name a range: 我正在使用以下代码命名范围:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var rangeToName = sheet.getRange(column, column - 1, 1,values.length + rowOffset);
var rangeName = 'F' + '2';
ss.setNamedRange(rangeName, rangeToName); // SCRIPT CRASHES HERE
When executing this script, it fails with the error message: The name you specified for this range is not a valid name.
执行此脚本时,它失败并显示错误消息:
The name you specified for this range is not a valid name.
I get this error whenever I use a concatenated string (it does not matter if I use to delimit the string with '
or "
). 每当我使用串联字符串时,都会出现此错误(是否使用
'
或"
分隔字符串都没有关系)。
How can I create the name of a range by concatenating two strings or a string and number? 如何通过连接两个字符串或一个字符串和数字来创建范围的名称?
As indicated: 如..所示:
The specified range name is ambiguous with a cell reference.
指定的范围名称与单元格引用不明确。
For more information, see Named and protected ranges . 有关更多信息,请参阅命名和保护范围 。
I have found the error: 我发现了错误:
The name for the range may not look like a reference to a cell, eg "F2" is an invalid name as it could be a cell. 该范围的名称可能看起来不像是对单元格的引用,例如,“ F2”是无效名称,因为它可能是单元格。 A name may not contain a "-" character.
名称中不能包含“-”字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.