简体   繁体   English

Google Spreadsheet:如何使用Google Apps脚本命名范围

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

相关问题 如何使用Google Apps脚本自动下载Google电子表格数据 - how to automatically download Google spreadsheet data using Google Apps script 如何使用 Google Apps 脚本将公式()设置为范围? - How to setFormulas() to a range using Google Apps Script? 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? 使用 Google Apps 脚本将数据范围从一个 Google 电子表格导出到另一个 - Export Range of Data from One Google Spreadsheet to Another using Google Apps Script 如何使用Google Apps脚本划掉电子表格的一行(不要删除它!)? - How to cross out a row of a spreadsheet (not to remove it !) using google apps script? 如何使用Google Apps脚本将特定的行从3个Google电子表格复制到另一个电子表格 - How to copy specific rows from 3 google spreadsheet to another spreadsheet using google apps script 使用Apps脚本从Google电子表格添加到Google文档 - Adding to a Google Doc from a Google Spreadsheet Using Apps Script 谷歌应用程序脚本 html 到电子表格 - Google apps script html to spreadsheet 如何判断Google Spreadsheet的Google Apps脚本中两个单元格是否相等 - How to tell if two cells are equal in Google Apps Script for Google Spreadsheet 如何在 Google 电子表格的 Google Apps 脚本中解析 JSON - How to parse JSON in Google Apps Script for Google Spreadsheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM